开发者

How to implement offline reading in my app

开发者 https://www.devze.com 2023-02-05 22:47 出处:网络
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 con开发者_Go百科tent is loaded from the disk but how

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 con开发者_Go百科tent 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


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];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消