如何在 iPhone 上以编程方式清除浏览器缓存? [英] How do I clear the browser cache programmatically on the iPhone?

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

问题描述

我正在为我的 iOS 大本营客户端应用程序使用新的 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];
    }
}

这篇关于如何在 iPhone 上以编程方式清除浏览器缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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