如何在我的应用程序中实现离线阅读
问题描述:
我想为我在iphone上开发的新闻应用程序实现离线阅读。我目前使用SDURLCache,并且我可以看到内容是从磁盘加载的,但是如何在不启动新的url连接的情况下查找给定url中是否存在缓存中的某些内容?如何在我的应用程序中实现离线阅读
或者如果有其他方法可以做,请让我知道。
THX
答
您可能能够做到这一点:
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];
}