2014-12-01 91 views
0

我使用的鑰匙串,像這樣的iOS刪除鑰匙扣價值

[keychain setValue:nil forKey:CFBridgingRelease(kSecAttrAccount)]; 

但是,我只看到這一點:

setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key acct. 

像明智的,當我使用這個:

[keychain setNilValueForKey:CFBridgingRelease(kSecAttrAccount)]; 

我得到這個:

setNilValueForKey]: could not set nil as the value for the key acct. 

我使用的是蘋果的KeychainItemWrapper,我會怎麼做這是否正確?

+0

通常你需要刪除的項目,你不能用'nil'值直接更新,'SecItemDelete(...)'方法將爲你做這個工作而不會崩潰。 – holex 2014-12-01 16:17:01

回答

1

通常要刪除一個項目,生成查詢,您通常會執行查詢,然後使用「SecItemDelete」。

這樣的 -

NSMutableDictionary *query = [self getQueryForKey:key]; 
OSStatus status = SecItemDelete((__bridge CFDictionaryRef)query); 
if(status != errSecSuccess) { 
    ... 
} 

如果您正在使用的keyChainWrapper你可以做 -

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil]; 
    [keychain resetKeychainItem]; 
+0

非常感謝:) – 2014-12-01 16:29:30