I am working on an app where few HTML,CSS files are downloaded from the server and loaded in the webview like this
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSURL *url = [NSURL fileURLWithPath:htmlfile];
htmlLoadRequest = [NSURLRequest requestWithURL:url];
[self.objwebview loadRequest:htmlLoadRequest];
In the webview delegate method i have this piece of code
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if(request.cachePolicy != NSURLRequestReloadIgnoringLocalCacheData) {
NSURLRequest* noCacheRequest = [[NSURLRequest alloc] initWithURL:request.URL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:request.timeoutInterval];
[webView loadRequest:noCacheRequest];
} // further code to do other stuff
In the viewWillDisappear method i have this piece of code
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.objwebview stopLoading];
[self.objwebview setDelegate:nil];
if (htmlLoadRequest) {
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:htmlLoadRequest];
}
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSString *htmlfile = [HTML_SERVER_FILES stringByAppendingPathComponent:@"CoverPage.html"];
self.objwebview = nil;
}
The place where i face the problem is that when i download the files for the first time then everything works fine but when i update few of my html files and then download them from the server then in that case what happens is i still see the first html files and their images.
This means that somewhere the webview is still maintaining the cache info for the first set that was downloaded and is not clearing it.
Also when my viewcontroller loads in the view will appear method i call this code
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
sharedCache = nil;
but nothing happens still i see the same old HTML files which where downloaded from the server at the first place.
The only way to see the updated set is to kill the app and then launch it again which i find should not be done as it creates a bad user exp. So please help me out on how to resolve this issue.
Update : I went through this URL where it says that its a bug in iOS 7