Issue with UIWebView caching pages

2019-09-09 09:05发布

问题:

I'm loading a remote html page into a UIWebView, the page is held on my mac book pro using and made available via OS X's built in Apache server.

I've noticed that if I load the page in the UIWebView, then make changes to the page and reload it then the changes are not reflected, hence it must presumably be being cached somewhere. I get this behavior even if I quit the app containing the UIWebView and re-launch it.

Where is the web page being cached? Is it possible to force the UIWebView to get the latest updated page?

回答1:

Try this -

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest];

This would remove a cached response for a specific request. There is also a call that will remove all cached responses for all requests ran on the UIWebView:

[[NSURLCache sharedURLCache] removeAllCachedResponses];