2014-12-01 92 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