ikzjfr0
ikzjfr0

Reputation: 767

NSURLSession cache does not work in iOS8

I have following code, it works fine in iOS7, but does not in iOS8.In iOS8, the app always use the cache even I have set NSURLRequestReloadIgnoringCacheData:

NSURL *url = [NSURL URLWithString:k_Chapter_URL];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];

NSURLSessionConfiguration *sessionConfig =
[NSURLSessionConfiguration defaultSessionConfiguration];
sessionConfig.requestCachePolicy = NSURLRequestReloadIgnoringCacheData;
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig];

[[session dataTaskWithRequest:request
            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

            }] resume];

Is there anybody have similar situation with me?

Upvotes: 5

Views: 801

Answers (1)

Eric Y
Eric Y

Reputation: 1697

I think this is a bug in iOS 8. I was able to use resetWithCompletionHandler to force the cache to clear.

[session resetWithCompletionHandler:^{
    [[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

        }] resume];
}];

Upvotes: 1

Related Questions