문제

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?

도움이 되었습니까?

해결책 2

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.

다른 팁

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'.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top