简体   繁体   English

iOS移除钥匙串价值

[英]iOS Remove Keychain Value

I'm using the Keychain like so: 我像这样使用钥匙串:

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

And wish to remove (null the value) like so: 并希望像这样删除(使值无效):

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

However, i only see this: 但是,我只看到以下内容:

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

Like wise, when i use this: 就像明智的,当我使用这个:

[keychain setNilValueForKey:CFBridgingRelease(kSecAttrAccount)];

I get this: 我得到这个:

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

I'm using apple's KeychainItemWrapper, How would i do this correctly? 我正在使用苹果的KeychainItemWrapper,我该如何正确执行?

In general to delete an item, generate the query you will normally do to fetch it, then use "SecItemDelete". 通常,要删除项目,请生成通常要提取的查询,然后使用“ SecItemDelete”。

Like this - 像这样 -

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

If you're using the keyChainWrapper you can do - 如果您使用的是keyChainWrapper,则可以-

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM