Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. [op setCredentialPersistence:NSURLCredentialPersistenceNone];
  2. [op setUsername:username password:password];
  3.  
  4. - (void) clearNSURLCredentialCache {
  5.  
  6. // clear any URL caches
  7. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  8. NSLog(@"Deleting NSURLCache.");
  9.  
  10. // reset the credentials cache...
  11. NSDictionary *credentialsDict = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
  12.  
  13. if ([credentialsDict count] > 0) {
  14. // the credentialsDict has NSURLProtectionSpace objs as keys and dicts of userName => NSURLCredential
  15. NSEnumerator *protectionSpaceEnumerator = [credentialsDict keyEnumerator];
  16. id urlProtectionSpace;
  17.  
  18. // iterate over all NSURLProtectionSpaces
  19. while (urlProtectionSpace = [protectionSpaceEnumerator nextObject]) {
  20. NSEnumerator *userNameEnumerator = [[credentialsDict objectForKey:urlProtectionSpace] keyEnumerator];
  21. id userName;
  22.  
  23. // iterate over all usernames for this protectionspace, which are the keys for the actual NSURLCredentials
  24. while (userName = [userNameEnumerator nextObject]) {
  25. NSURLCredential *cred = [[credentialsDict objectForKey:urlProtectionSpace] objectForKey:userName];
  26. NSLog(@"cred to be removed: %@", cred);
  27. [[NSURLCredentialStorage sharedCredentialStorage] removeCredential:cred forProtectionSpace:urlProtectionSpace];
  28. }
  29. }
  30. }
  31.  
  32. // clear all cookies
  33.  
  34. NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  35. for (NSHTTPCookie *sessionCookie in cookieStorage.cookies) {
  36. NSLog(@"Deleting cookie: %@", sessionCookie);
  37. [cookieStorage deleteCookie:sessionCookie];
  38. }
  39. }
  40.  
  41. [op setCredentialPersistence:NSURLCredentialPersistenceNone];
  42. [op addHeader:@"Cookie" withValue:@""];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement