Long story short, I just updated to Xcode 6 to check how my app works on iOS 8. I noticed that it doesn't use the cache even though it should. I'm using AFNetworking setting the cachePolicy like this:
sessionManager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
I still have an iOS 7 device in which I tested the same code and it works there as expected.
Does anyone have a solution for this, or do we need to wait for Apple to fix it?
iOS 8.0.1 was released on September 24, 2014, as the first update to iOS 8. The update was meant to bring various bug fixes; however, the update was withdrawn due to an issue that disabled Touch ID and cellular network connectivity on some models.
The second security hole fixed in iOS 14.8 is in the Apple WebKit browser engine, where processing malicious web content could allow an adversary to execute code. Apple believes both vulnerabilities have been exploited by attackers, so it recommends you install iOS 14.8 now.
iOS 8 is the eighth major release of the iOS mobile operating system developed by Apple Inc., being the successor to iOS 7. It was announced at the company's Worldwide Developers Conference on June 2, 2014, and was released on September 17, 2014. It was succeeded by iOS 9 on September 16, 2015.
^ Langley, Hugh (September 26, 2014). "iOS 8.0.2 is now available to download, and this one shouldn't break your iPhone". TechRadar. Future plc.
I'm almost certain that iOS 8.0 has broken NSURLSession
's ability to cache HTTP response data. I've opened a radar with Apple about this issue.
Here's some sample code I wrote to prove this:
NSURLSession *session = [NSURLSession sharedSession];
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024
diskCapacity:32 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSURL *URL = [NSURL URLWithString:@"http://i.imgur.com/b5pyONe.jpg"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:5];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"Error occurred");
} else {
NSLog(@"Fetched resource!");
}
dispatch_semaphore_signal(semaphore);
}];
[task resume];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
request = [NSURLRequest requestWithURL:URL
cachePolicy:NSURLRequestReturnCacheDataDontLoad
timeoutInterval:5];
task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"Something bad happened: %@", error);
} else {
NSLog(@"Fetched resource!");
}
}];
[task resume];
Even creating your own NSURLSession
-- with an NSURLSessionConfiguration
that has an NSURLCache
that you create yourself -- won't fix this issue. For now, if you need cached responses badly, you have to use NSURLConnection
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With