Created
August 31, 2010 14:06
-
-
Save veader/559071 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)clearCaches { | |
// clear any URL caches | |
[[NSURLCache sharedURLCache] removeAllCachedResponses]; | |
// clear any cookie caches | |
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; | |
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@/", kAPIHost]]; | |
for (NSHTTPCookie *cookie in [cookieStorage cookiesForURL:url]) { | |
[cookieStorage deleteCookie:cookie]; | |
} | |
// attempt to clear any credential caches | |
NSURLCredentialStorage *credentialStorage = [NSURLCredentialStorage sharedCredentialStorage]; | |
NSDictionary *credentialsDicationary = [credentialStorage allCredentials]; | |
for (NSURLProtectionSpace *space in [credentialsDicationary allKeys]) { | |
NSDictionary *spaceDictionary = [credentialsDicationary objectForKey:space]; | |
for (id userName in [spaceDictionary allKeys]) { | |
NSURLCredential *credential = [spaceDictionary objectForKey:userName]; | |
[credentialStorage removeCredential:credential forProtectionSpace:space]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment