Iphonecachingapplicationcookiescacheperformance
I actually think it may retain cached information when you close out the the UIWebView. I ' ve tried removing a uiwebview from my uiviewcontroller, releasing it, then creating a new one. The new one remembered exactly where I am at while I went back to an address without have to reload everything (it remem Bered my previous UIWebView is logged in).
So a couple of suggestions:
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest];
This would remove a cached response for a specific request. There is also a call that would remove all cached responses for all requests ran on the UIWebView:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
After this, you can try deleting any associated cookie with the UIWebView:
For(Nshttpcookie *Cookie in[[Nshttpcookiestorage Sharedhttpcookiestorage] Cookies) { if ([[cookie domain] Isequaltostring: somensstringurldomain) { [[nshttpcookiestorage Sharedhttpcookiestorage]:cookie];}}
Let me know where this gets you.
I had nearly the same problem. I wanted the webview cache to being cleared, because everytime i reload a local webpage in an UIWebView, the old one is shown . So I found a solution by simply setting thecachepolicy property of the request. Use a nsmutableurlrequest to set the This property. With all this everything works fine with reloading the UIWebView.
Nsurl*Url= [Nsurl Fileurlwithpath:myhtmlfilepath]; nsmutableurlrequest *Request = [nsmutableurlrequest requestwithurl: URL]; [request Setcachepolicy:nsurlrequestreloadignoringlocalcachedata]; [self. WebView loadrequest:request];
Hope that helps!
Don ' t disable caching completely, it ' ll hurt your app performance and it ' s unnecessary. The important thing is to explicitly configure the cache in app startup and purge it when necessary.
So in application:DidFinishLaunchingWithOptions:
configure the cache limits as follows:
- (BOOL)Application:(UIApplication *)Application Didfinishlaunchingwithoptions:(Nsdictionary *)Launchoptions{IntCachesizememory= 4*1024*1024; 4MBIntCachesizedisk= 32*1024*1024; 32MBNsurlcache *sharedcache = [[[nsurlcache Alloc]:cachesizememory diskcapacity:cachesizedisk diskpath:@ "Nsurlcache" Autorelease; [nsurlcache:sharedcache];//... other launching Code}
Once you have it properly configured and then if you need to purge the cache (for example in applicationDidReceiveMemoryWarning
or if you close a UIWebView
) Just do:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
And you'll see the memory is recovered. I blogged about this issue here:http://twobitlabs.com/2012/01/ios-ipad-iphone-nsurlcache-uiwebview-memory-utilization/
You can disable the caching by doing the following:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];[NSURLCache setSharedURLCache:sharedCache];[sharedCache release];
How the iphone empties the UIWebView cache