Answer the question
In order to leave comments, you need to log in
Why can't UIWebView be trained to access the local cache while reloading the same web page?
Good afternoon guys!
Faced a problem - it is not possible to disaccustom UIWebView to access the local cache during reloading of the same web page. I need each new request to go to the Internet (relevant only for iOS 7).
Here's what's available:
1) A custom NSURLProtocol that just keeps track of http requests.
2) There is a UIWebView in the first UIViewController . In this UIWebView we load the website:
NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://site.ru"]
cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
3) While loading the page in NSURLProtocol, we conditionally see 20 requests to this site.ru (images, css, js, etc. are loaded) NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:
4 * 1024 * 1024 diskCapacity:32 * 1024 * 1024 diskPath:@"dir"];
[NSURLCache setSharedURLCache:URLCache];
2) Before sending the request, call:[[NSURLCache sharedURLCache] removeCachedResponseForRequest:(NSURLRequest *)];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
3) Clear the cache directory NSCachesDirectory (horror!) - (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:
(NSCachedURLResponse *)cachedResponse {
return nil; }
6) Add the time parameter site.ru?timestamp=21324353 to the address (horror!) - (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request {
return nil; }
Answer the question
In order to leave comments, you need to log in
And try to do in paragraph 2 also like this
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
they say sometimes it helps)
PS colleague, well, you put tags) no one will find you like that)
It's strange, of course. because the request contains the NSURLRequestReloadIgnoringCacheData flag. Those. should not store anything in the cache. If this is only on ios7, then this is some kind of flaw with apple. How does the same code behave on ios6?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question