質問

When I start a request with the NSURLRequestReturnCacheDataElseLoad policy I expect to get the result from the NSURLCache if any, no matter how old it is. However, the system always tries to reach the server the request points to and returns an error if the server doesn't answer.

I use the UIImageView category of AFNetworking for the request.

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

This will not set the image even if asking the NSURLCache directly will return a valid NSCachedURLResponse.

The app is running on iOS6 only, so there should be no problems with on-disk cache as far as I know?!

Any help is appreciated! Thanks!

役に立ちましたか?

解決

This is a know issue. Please refer this discussion on AFNetworking github page for a workaround.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top