ios - NSURLConnection/AFNetworkingOperation 未使用 NSURLCache

标签 ios ios6 afnetworking nsurlcache

当我使用 NSURLRequestReturnCacheDataElseLoad 策略启动请求时,我希望从 NSURLCache 获取结果(如果有),无论它有多旧。但是,系统始终尝试访问请求指向的服务器,如果服务器没有应答,则返回错误。

我使用 AFNetworkingUIImageView 类别来执行请求。

NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
__weak __typeof(self) weakSelf = self;
NSLog(@"[%@] %@", request.URL, [[NSURLCache sharedURLCache] cachedResponseForRequest:request]); // this returns an instance of NSCachedURLResponse!
[self setImageWithURLRequest:request placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
    __typeof(weakSelf) self = weakSelf;
    self.image = image;
} failure:NULL];

即使直接询问 NSURLCache 将返回有效的 NSCachedURLResponse,也不会设置图像。

该应用程序仅在 iOS6 上运行,因此据我所知,磁盘缓存应该没有问题?!

感谢任何帮助!谢谢!

最佳答案

这是一个已知问题。请引用 AFNetworking github page 上的讨论寻求解决方法。

关于ios - NSURLConnection/AFNetworkingOperation 未使用 NSURLCache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16541991/

相关文章:

ios - NSURL 路径的带反斜杠的转义序列

ios - NSURLSession:后台上传然后调用服务api

ios - 下载时播放 Mp4 和 Mp3 文件

ios - 如何在 ios swift 中部分更改背景 View 颜色

ios - 如何快速将 double 转换为字节数组?

ios - 相机预览未填满屏幕

ios - NSArray 在 iOS6 中有 5 个对象,但在 iOS5 中有 4 个对象?

objective-c - iOS5 TabBar 字体和颜色

iphone - 删除后documents目录下的文件

xcode - UICollectionViewCell 将被显示/被显示?