2

My iOS application is downloading data from an RSS feed. I know I need to save the data.

Since, the application is having to download the data remotely -- it takes several seconds for the table view to update with the RSS data items.

I want it to only download new data if the RSS feed data has changed.

I'm setting up saving the data. But, I'm not sure how to check if the RSS feed has been updated without having to download the entire RSS feed.

Is there anyway of requesting an rss feed but only getting the pubBuildDate returned?

Meaning if the pubBuildDate is newer than last build date saved -- then I would download all of the rss feed and parse it. Otherwise, I would just load saved data.

UPDATE 1:

When I get the HTTP headers back from my request -- the status code isn't there nor is If-Modified-Since.

I've tried setting the value for If-Modified-Since and adding it to the HTTP header response but I haven't had any luck at getting this to work.

I know that if the status code is 200 then that means nothing has changed and if you get a 304 back then there is new content.

Does anyone know how to send If-Modified-Since along with a URL request?

Reference Links: http://www.feedthebot.com/ifmodified.html

Sandy D.
  • 3,166
  • 1
  • 20
  • 31
  • Do you control the RSS feed? Does it provide sensible-looking Last-Modified/ETag HTTP headers? (NB: These are HTTP headers, *not* in the body of the request; they're part of the HTTP standard, not the RSS standard.) The idea you're trying to implement is normally called "conditional GET" in HTTP, if that helps you look anything up. – Matt Gibson Nov 17 '14 at 17:31
  • @MattGibson The RSS feed is coming from a plugin for Wordpress -- so I don't have much control over it. How do you view Last-Modified/Etag HTTP headers on an RSS feed using a MAC? – Sandy D. Nov 17 '14 at 17:38
  • @MattGibson: I tried using NSMutableURLRequest to print out allHTTPHeaders for requesting the RSS feed. And nothing is returned for the `urlRequest.allHTTPHeaderFields`. So, I'm confused. Any ideas how to view the HTTP headers? – Sandy D. Nov 17 '14 at 18:04
  • 1
    It's the *response* you want to look at the header fields for, not the request. Make the request, and inspect the allHTTPHeaderFields property of the NSHTTPURLResponse you get back. – Matt Gibson Nov 17 '14 at 18:26
  • @MattGibson: You rock! =) Here is what I did: `NSURL *url = [NSURL URLWithString:self.url]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; NSHTTPURLResponse *response; [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil]; NSLog(@"headers: %@", [response allHeaderFields]);` I'm assuming that SynchronousRequest is the one I need to do? I was able to get the header information and it contains the info I need. I guess I just make the request and then I would parse it only if the date for Last-Modified had changed? – Sandy D. Nov 17 '14 at 18:28
  • If the HTTP caching header looks good, then my guess would be that you should use whatever built-in caching mechanisms there are in Apple's HTTP transfer classes—you probably only need to do minimal work. However, I've not done this myself, so the question's probably best answered by someone with more experience. (But effectively, you should be able to turn on caching in NSURLSession, etc., so that calls just use an HTTP cache without writing a load of manual code to cache stuff.) – Matt Gibson Nov 17 '14 at 20:55
  • @MattGibson Looks like the Last-Modified header isn't updated when the RSS feed is updated. Any ideas why the Last-Modified header wouldn't update? – Sandy D. Nov 19 '14 at 18:17
  • @SandyD. - The headers returned are likely defined by the implementation of the rss feed service. I would look into query parameters or testing the HTTP/1.1 HEAD method to verify results are the same as GET. – TheHairyGun Nov 20 '14 at 20:16
  • @TheHairyGun I haven't had any luck yet. It was suggested that I should send an If-Modified-Since along with my HTTP request but I haven't found anything online that explains how to do this. Any ideas? Thank you for commenting. – Sandy D. Nov 20 '14 at 20:48

0 Answers0