How clear UIWebView cache

2019-04-13 18:28发布

How to clear the cache of a UIWebView?

I am making a simple application (with only three buttons (back, forward, refresh) and a UIWebView) and I realized that in my Documents & Data iPhone gets a very high value of Cache. I already looked at various documents and posts (even here at StackOverflow) but none solved the problem. If you need lines of codes, ask.

2条回答
聊天终结者
2楼-- · 2019-04-13 18:52
[[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];

After that, you can try deleting any associated cookies with the UIWebView:

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {

    if([[cookie domain] isEqualToString:someNSStringUrlDomain]) {

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
}
查看更多
聊天终结者
3楼-- · 2019-04-13 18:57

its so simple

[[NSURLCache sharedURLCache] removeAllCachedResponses];
查看更多
登录 后发表回答