我想为我在 iPhone 上开发的新闻应用程序实现离线阅读。我目前使用 SDURLCache,我可以看到内容是从磁盘加载的,但是我如何在不启动新的 url 连接的情况下找到给定 url 的缓存中是否已经有内容?
或者如果有其他方法可以做到这一点,请告诉我。
谢谢
最佳答案
你可以这样做:
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];
}
关于iphone - 如何在我的应用中实现离线阅读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4728889/