清除UIWebview缓存 [英] Clearing UIWebview cache

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

问题描述

我使用UIWebview加载网页使用 loadRequest:方法,当我离开那个场景,我调用 [self.webView stopLoading];



在第一次启动的活动监视器中,我看到真实内存增加了4MB,并且在多次启动/加载真正的内存不增加。它只增加一次。



我检查了webview的保留计数。这是正确的,即0.我认为UIWebView正在缓存一些数据。如何避免缓存或删除缓存数据?

我实际上认为它可能会保留缓存的信息,当你关闭了<$ c $

c> UIWebView
。我试图从我的 UIViewController 中删除​​ UIWebView ,释放它,然后创建一个新的。当我回到一个地址,而不必重新加载任何东西(它记住我以前的 UIWebView 已经登录)时,新的人记住了我在哪里。



有几个建议:

  [[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest]; 

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

  [[NSURLCache sharedURLCache] removeAllCachedResponses];之后,您可以尝试使用 UIWebView 删除任何关联的cookie, code>:

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

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

[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}

让我知道在哪里可以找到你。


I have used UIWebview to load a web page using loadRequest: method, when I leave that scene I call [self.webView stopLoading]; and release the webView.

In activity monitor on first launch i have seen that the real memory increased by 4MB, and on multiple launches/loading the real memory doesn't increase. It is increasing only once.

I have checked the retain count of webview. It is proper i.e., 0. I think UIWebView is caching some data. How do I avoid caching or remove cached data? Or is there another reason for this?

解决方案

I actually think it may retain cached information when you close out the UIWebView. I've tried removing a UIWebView from my UIViewController, releasing it, then creating a new one. The new one remembered exactly where I was at when I went back to an address without having to reload everything (it remembered my previous UIWebView was logged in).

So a couple of suggestions:

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

Let me know where that gets you.

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

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