如何在iPhone上以编程方式清除浏览器缓存?
问题描述:
我正在为iOS basecamp客户端应用程序使用新的Basecamp API.我希望用户能够注销和切换帐户.但是由于每次请求授权时都不会使用存储在浏览器缓存中的帐户凭据,因此无法使用. 我发现我需要刷新浏览器缓存才能做到这一点.如何清除浏览器缓存?
I am using the new Basecamp API for my iOS basecamp client app. I want the user to be able to logout and switch accounts. But I can't as the account credentials stored in the browser cache are used every time I request authorization. I figured out I would need to flush browser cache to do this. How do I clear the browser cache?
答
[[NSURLCache sharedURLCache] removeAllCachedResponses];
之后,您可以在UIWebView中删除所有与之关联的Cookie:
After that, you can deleting any associated cookies with in the UIWebView:
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
if([[cookie domain] isEqualToString:someNSStringUrlDomain]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}