How to clear browser cache programmatically on iPhone?

I am using the new Basecamp API for my basecamp iOS client application. I want the user to be able to log out and switch accounts. But I can’t, because the account credentials stored in the browser cache are used every time I request authorization. I realized that I would need to clear my browser cache in order to do this. How to clear browser cache?

+5
source share
1 answer
[[NSURLCache sharedURLCache] removeAllCachedResponses];

After that, you can delete any related cookies using UIWebView:

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

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

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
}
+8
source

All Articles