Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [op setCredentialPersistence:NSURLCredentialPersistenceNone];
- [op setUsername:username password:password];
- - (void) clearNSURLCredentialCache {
- // clear any URL caches
- [[NSURLCache sharedURLCache] removeAllCachedResponses];
- NSLog(@"Deleting NSURLCache.");
- // reset the credentials cache...
- NSDictionary *credentialsDict = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
- if ([credentialsDict count] > 0) {
- // the credentialsDict has NSURLProtectionSpace objs as keys and dicts of userName => NSURLCredential
- NSEnumerator *protectionSpaceEnumerator = [credentialsDict keyEnumerator];
- id urlProtectionSpace;
- // iterate over all NSURLProtectionSpaces
- while (urlProtectionSpace = [protectionSpaceEnumerator nextObject]) {
- NSEnumerator *userNameEnumerator = [[credentialsDict objectForKey:urlProtectionSpace] keyEnumerator];
- id userName;
- // iterate over all usernames for this protectionspace, which are the keys for the actual NSURLCredentials
- while (userName = [userNameEnumerator nextObject]) {
- NSURLCredential *cred = [[credentialsDict objectForKey:urlProtectionSpace] objectForKey:userName];
- NSLog(@"cred to be removed: %@", cred);
- [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:cred forProtectionSpace:urlProtectionSpace];
- }
- }
- }
- // clear all cookies
- NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
- for (NSHTTPCookie *sessionCookie in cookieStorage.cookies) {
- NSLog(@"Deleting cookie: %@", sessionCookie);
- [cookieStorage deleteCookie:sessionCookie];
- }
- }
- [op setCredentialPersistence:NSURLCredentialPersistenceNone];
- [op addHeader:@"Cookie" withValue:@""];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement