@@ -129,4 +129,37 @@ + (NSArray *)getAllTeamId{
129129 return plainCertifcates;
130130}
131131
132+ #pragma mark - Remove All Cache, Cookies and Credentials
133+ + (void )removeAllStoredCredentials {
134+ // Delete any cached URLrequests!
135+ NSURLCache *sharedCache = [NSURLCache sharedURLCache ];
136+ [sharedCache removeAllCachedResponses ];
137+
138+ // Also delete all stored cookies!
139+ NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage ];
140+ NSArray *cookies = [cookieStorage cookies ];
141+ id cookie;
142+ for (cookie in cookies) {
143+ [cookieStorage deleteCookie: cookie];
144+ }
145+
146+ NSDictionary *credentialsDict = [[NSURLCredentialStorage sharedCredentialStorage ] allCredentials ];
147+ if ([credentialsDict count ] > 0 ) {
148+ // the credentialsDict has NSURLProtectionSpace objs as keys and dicts of userName => NSURLCredential
149+ NSEnumerator *protectionSpaceEnumerator = [credentialsDict keyEnumerator ];
150+ id urlProtectionSpace;
151+ // iterate over all NSURLProtectionSpaces
152+ while (urlProtectionSpace = [protectionSpaceEnumerator nextObject ]) {
153+ NSEnumerator *userNameEnumerator = [[credentialsDict objectForKey: urlProtectionSpace] keyEnumerator ];
154+ id userName;
155+ // iterate over all usernames for this protectionspace, which are the keys for the actual NSURLCredentials
156+ while (userName = [userNameEnumerator nextObject ]) {
157+ NSURLCredential *cred = [[credentialsDict objectForKey: urlProtectionSpace] objectForKey: userName];
158+ // NSLog(@"credentials to be removed: %@", cred);
159+ [[NSURLCredentialStorage sharedCredentialStorage ] removeCredential: cred forProtectionSpace: urlProtectionSpace];
160+ }
161+ }
162+ }
163+ }
164+
132165@end
0 commit comments