2013-02-24 275 views
2

如何清除UIWebView的缓存?如何清除UIWebView缓存

我正在做一个简单的应用程序(只有三个按钮(回来,转发,刷新)和一个UIWebView),我意识到在我的文档&数据iPhone获得非常高的缓存价值。我已经看过各种文档和帖子(甚至在StackOverflow中),但没有解决问题。 如果您需要代码行,请询问。

回答

0

其如此简单

[[NSURLCache sharedURLCache] removeAllCachedResponses]; 
6
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest]; 

这将消除对特定请求的缓存的响应。还有一个电话,将删除所有请求都缓存的响应上的UIWebView跑:

[[NSURLCache sharedURLCache] removeAllCachedResponses]; 

之后,你可以尝试删除任何相关的cookie与一个UIWebView:

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

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

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

方法中,我将不得不把这些代码(这是Naoe到现在为止) – 2013-02-24 18:14:23