clearing a webviews cache for local files

守給你的承諾、 提交于 2019-12-03 12:46:55

WebKit maintains its own caches in addition to the standard NSURLCache one. You have no control over it.

Realistically, you have to make sure your code behaves well under low memory warnings, and trust that UIWebView will do the same.

I'm not sure if your problem was loading cached data, or simple that the last requested URL was cached, and therefore not triggering a new document to load. That seemed to be the case for me, so I used this very dirty trick:

_urlRequestCacheBust = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];

And for each new web request:

- (void)webViewLoadURL:(NSURL *)url
{
    [[_webView mainFrame] loadRequest:_urlRequestCacheBust];

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
    [[_webView mainFrame] loadRequest:urlRequest];
}

*shudder*

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!