I need to download an XML file, using HTTP protocol, to use it locally on my iPhone app. Occasionally this file will be updated on the server, but not very often.
How do I compare the already downloaded file that is already in the Documents folder, with the one on the server, just downloading it if the content has been updated on the server?
The first time you download the file, save the date from the Last-Modified header of the response. You can pull it out of the
NSHTTPURLResponseobject.On subsequent runs, put that date in the
If-Modified-Sinceheader of theNSURLRequest. If the file on the server hasn’t changed, thestatusCodeof theNSHTTPURLResponseshould be 304 (which means “Not Modified”) and the body of the response should be empty.