Below given code works in iOS 6 but it does not work on iOS 7.
NSCachedURLResponse cachedURLResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data userInfo:nil storagePolicy:NSURLCacheStorageAllowed];
[[NSURLCache sharedURLCache] storeCachedResponse:cachedURLResponse forRequest:request];
NSLog(@"Cached response is %@", [[NSURLCache sharedURLCache] cachedResponseForRequest:request]);
In iOS 6 I am getting the cached response data but in iOS 7 it returns null. I have set the NSURLCache object in App delegate using:
NSURLCache *urlCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024
diskCapacity:2 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:urlCache];
What is the reason of caching not working in iOS 7?
Caching mechanism relies on HTTP headers. Check returned HTTP headers if caching is allowed in first place. You may do it with web proxies like 'Charles'.
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