iOS 删除钥匙串值



我像这样使用钥匙串:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"LoginData" accessGroup:nil];
[keychain setObject:responseObject[@"TOK"] forKey:CFBridgingRelease(kSecAttrAccount)];

并希望像这样删除(空值):

[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.

我正在使用Apple的KeychainItemWrapper,我该如何正确执行此操作?

通常,要删除项目,请生成通常执行的查询以获取它,然后使用"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];

最新更新