UIWebView如何清除缓存 [英] How clear UIWebView cache

查看:170
本文介绍了UIWebView如何清除缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除UIWebView的缓存?

How to clear the cache of a UIWebView?

我正在制作一个简单的应用程序(只有三个按钮(后退,前进,刷新)和一个UIWebView)和我意识到在我的文件和数据iPhone获得了非常高的Cache值。我已经查看了各种文档和帖子(甚至在StackOverflow这里),但没有解决问题。
如果您需要代码行,请询问。

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.

推荐答案

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest];

这将删除特定请求的缓存响应。还有一个调用将删除在UIWebView上运行的所有请求的所有缓存响应:

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];

之后,您可以尝试使用UIWebView删除任何关联的cookie:

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];
    }
}

这篇关于UIWebView如何清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆