Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clear the browser cache programmatically on the iPhone?

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?

like image 634
Shyam Bhat Avatar asked Sep 18 '12 10:09

Shyam Bhat


1 Answers

[[NSURLCache sharedURLCache] removeAllCachedResponses];

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];
    }
}
like image 169
Romit M. Avatar answered Oct 02 '22 12:10

Romit M.