Yannis
Yannis

Reputation: 6157

How to implement offline reading in my app

I would like to implement offline reading for a news application I have been developing on the iphone. I currently use SDURLCache and I can see the content is loaded from the disk but how can I find if there is already something in the cache for the given url without starting a new url connection?

or if there is some other way to do that please let me know.

thx

Upvotes: 3

Views: 418

Answers (1)

Tobias
Tobias

Reputation: 4397

You might be able to do this:

NSData* cacheForUrl(NSString *aUrl) {
  SDURLCache *cache = [[SDURLCache alloc] init]; 
  NSCachedURLResponse *response = [cache cachedResponseForRequest:[NSUrlRequest requestWithURL:aUrl];
  if(!response) {
    return @"URL not in cache";
  } //implicit else

  return [response data];
}

Upvotes: 1

Related Questions