iosobjective-cbasecamp

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?


Solution

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