我正在尝试删除在访问安全HTTP站点时编写的NSURLCredential。下面的代码可以从NSURLCredential
中删除NSURLCredentialStorage
,但即使我指定了:
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
没有重新加载缓存数据,我已经实现了这个方法:
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}
下次运行应用程序时,deleteStoredCredential会为“loginSiteName.com”找到新凭据并将其删除。我的问题是,我错过了什么,是否有其他我需要清除的地方,是否可以将凭证缓存在iPhone上?
-(void)deleteStoredCredential {
NSURLCredentialStorage *sharedCredentialStorage = [NSURLCredentialStorage sharedCredentialStorage];
NSDictionary *DICT_allProtectionSpaces = [sharedCredentialStorage allCredentials];
// DICT KEY = NSURLProtectionSpace
// DICT VALUE = NSDictionary
for(NSURLProtectionSpace *thisProtectionSpace in DICT_allProtectionSpaces) {
if([[thisProtectionSpace host] isEqualToString:@"loginSiteName.com"]) {
NSDictionary *DICT_allCredentials = [sharedCredentialStorage credentialsForProtectionSpace:thisProtectionSpace];
// DICT KEY = NSString (i.e. username)
// DICT VALUE = NSURLCredential
for(NSString *thisUserName in DICT_allCredentials) {
NSURLCredential *credentialToDelete = [DICT_allCredentials valueForKey:thisUserName];
NSLog(@"REMOVE UID: %@ WITH PWD: %@", [credentialToDelete user], [credentialToDelete password]);
[sharedCredentialStorage removeCredential:credentialToDelete forProtectionSpace:thisProtectionSpace];
}
}
}
}
答案 0 :(得分:2)
我发现了问题:我创建的用于访问网站的NSURLCredential
是使用NSURLCredentialPersistencePermanent
而不是NSURLCredentialPersistenceNone
创建的。因此,凭证被存储在iPhone钥匙串中。
答案 1 :(得分:0)
我还使用NSURLCredentialPersistenceNone来避免将凭证存储在存储中。 但我说我需要等待一些借调,如10秒,以清除旧凭证,然后启动新的凭证SSL证书客户端。
您是否在NSURLConnection类中注意到这种奇怪的行为?
谢谢你的帮助:)