Hi all what i want to do is to download plist from server http:// and i'd like to know how and where it is stored.
Can the iphone compare date from 2 plist files ? ?
thanks to all, if you do not want to post code or explain please link it. !Because i'm really stuck and need help
thanks
If you're downloading the file, you can use the Last-Modified header in the (e.g.) NSHTTPURLResponse object to determine if the file has been modified on the server since it was last modified locally. Use the -compare: method on two NSDate objects (one parsed from the header, one obtained from the local file system) to determine which is later.
Related
I've experimented with several ways on seeing if I need to update my user's UITableView data source only if the server one is newer. Over the past few years I've done these scenarios: 1: Having a seperate .txt file with a character as the version # then simply comparing them through code and downloading the new .plist, then saving that .txt to the user's NSDocumentDirectory along with the .plist to compare again in the future, and 2: Actually checking the server's file modification date, which worked even better, as there was no .txt file to download along with the .plist (the less stuff to download the better)
But, now I want to try a different way to account for the fact that I ship a .plist file in the App Bundle. Since the .plist file creation date is always later then the server date for new users, they don't get the new .plist file, whereas older users of the app get the new file. Sure, on the first app launch I could grab the server's modification date and overwrite the app's since I copy it from the main bundle to the NSDocumentDirectory, but I don't think I want to go that route, as I've never liked checking launch counts.
Basically, it needs to continue to be lightweight in network request time and be reliable like it's been for me. I was thinking about creating a version # key in my .plist and simply comparing that with the local .plist, but I highly doubt this will be as lightweight, as I would have to download the whole .plist into an NSDictionary first before I can compare the key values.
I'm really sorry this post is long, and I appreciate your help!
Why not ship the app with out the data_source.plist file and download it on first launch, or any other time it does not exist on disk (you never know). After that, you could send a HEAD request and check the modification date (maybe even the e-tag), and download as necessary.
UPDATE:
Depending on how much control you have over the server, you could add a hash of the file to the response headers (as mentioned in the comments: MD5,SHA*) along side Last-Modified.
You could add the data_source.plist to the bundle at build time, along with last_modified.plist where you can set the hash, last modified, and any other meta data you want, as starting point.
Checking for updates could look something like:
Send HEAD request for http://server.com/data_source.plist
Pull Last-Modified (and hash if you can send it) from the response headers
Validate against corresponding values in last_modifed.plist
Download updated data_source.plist if needed
If the download was successful, update last_modifed.plist with new meta data (last modified and has, be sure pull this from actual download response headers).
This way, the user has something to start with, and the app can download the resource when needed.
The advantage of a HEAD request is it is light weight since there is no message body, but returns the same response headers as a GET request. It is a common method to check if a resource has been updated. The trick with your scenario is to get a starting point onto the device at build time.
I Want to list all the file's urls. Files are present on a website. They are in a public directory in a website. No Ftp access is required to access the urls. So no ftp based programming is needed.
For example- www.mysite.com/myimages/(multiple files)
I want to store All the files URL path in NSMutableArray. Can anybody assist me or explain me the proper way to do this in iphone using objective c.
Hope to Get a Solution,
Thank You,
Tuhin Bhatt
I think below approach will be one to solve the problem.
You have to make a simple web-service api that will simple return the all url links in json / xml format. Then you parse the response and store those in a NSMutableArray
[NSPropertyListSerialization propertyListFromData:self.responseData
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc];
When the server is online, it sends the responseData. Now I want to save this data(obtained through the responseData in the code) directly to another plist in my app, so that I can retrieve the data later(when the server is offline) in the same format(without changing) and use it/pass it in the same way as it is being passed when my server is online. I am doing this so that the user of the app does not come to know whether the server is online/offline and still is able to give updates/feedback to the responseData (as he/she would give when the server is online). I don't want to break the responseData and save it, rather directly save it the way it is coming from the server.
Please let me know if more explanation is required.And thanks for all the answers that you would be giving :)
If you don't want to change anything I believe you should just download the plist as a file and not as data.
To save the file on the phone you should use NSFileManager, you can read about it here:NSFileManager reference + File System Programming Guide
You must pay attention to the place you save the plist according to apple "new" rules of data storage, you can read about it here:
Were you should save your files
Good luck
By using the ASIHTTPRequest and ASIDownloadCache i am able to continue with previous downloaded session.Now I don't want to use ASIDownloadCache.So,is there any alternatives to achieve it.
Thanks in advance.
If the server supports it, you can specify the Content-Range field in the header of your HTTP request and ask only for a small portion of the file at once. When you get all portions, you can assemble the file together.
You can set HTTP headers with NSMutableURLRequest setValue:#"0-1023/*" forHTTPHeaderField:#"Content-Range"];, this example downloads only the 1024 byte of the file. See also Content-Range in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
This way you can download the file in parts and next time when you want to resume the download you can continue it from the next part that you don't have yet.
I've not found a answer to this question anywhere, but this seems like a typical problem:
I have in my "Resources" Folder a XML File that my App needs to show some informations. But I have to check in my Server, if the server has a newer XML available, so I should replace my XML (in the resources folder) for this new one.
How can I achieve that?
Thanks in advance for any help!
I'm not sure you get write access to the Resources section. A better way to do it, is to download the folder to your "Documents" directory. Then when you app checks to load the XML file, it should see if there is a version in the documents directory and load that first. If it doesn't find a replacement one, then it uses the original version.
This means the original XML file can be used if there is some issue with the downloaded one. Which happens, either the network got cutoff and didn't finish, or the server gave the wrong xml file and it doesn't validate.
You can access the document directory using:
NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *destinationpath = [docPaths lastObject];
If you are wanting to check the versions, you can use an element inside the XML to give you the version number or you can use the Last-Modified date. An example of the version could be:
<myxml version="234">
Then you could check this value.
You can let the API, a method to check The most recent modified date. And in the client site, you can get your most recent modified date of the XML file and compare with the one in the server. You can get the description of the XML file and return true or false to replace.
U need some way to distinguish the new XML from the old one. I assume you have some mechanism to do that. Typically some kind of Version node inside the XML.
If the server's version and the one on ur phone is different, get the new one else don't do anything.