Reputation: 1757
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?
Upvotes: 5
Views: 1510
Reputation: 1757
I was doing a POST method and setting the http_body with the required NSData. In iOS 6, the response was being cached but this was not working in iOS 7.
So, now instead of setting http_body, we are appending the param in the url and making a request and caching is working now.
Upvotes: 0
Reputation: 2712
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'.
Upvotes: 1