gpt4 book ai didi

ios - iOS的钥匙串(keychain)服务,删除钥匙串(keychain)错误

转载 作者:行者123 更新时间:2023-12-01 17:01:57 28 4
gpt4 key购买 nike

我使用 iOS keychain wrapper 编写了一个项目存储用户名和密码,项目工作正常,直到昨天。
在我对项目运行 clean 命令后,项目崩溃:

- (void)writeToKeychain
{
NSDictionary *attributes = NULL;
NSMutableDictionary *updateItem = NULL;

// If the keychain item already exists, modify it:
if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery,
(CFTypeRef *)&attributes) == noErr)
{
// First, get the attributes returned from the keychain and add them to the
// dictionary that controls the update:
updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes];

// Second, get the class value from the generic password query dictionary and
// add it to the updateItem dictionary:
[updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass]
forKey:(id)kSecClass];

// Finally, set up the dictionary that contains new values for the attributes:
NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainData];

//Remove the class--it's not a keychain attribute:
[tempCheck removeObjectForKey:(id)kSecClass];

// You can update only a single keychain item at a time.
NSAssert(SecItemUpdate((CFDictionaryRef)updateItem,
(CFDictionaryRef)tempCheck) == noErr,
@"Couldn't update the Keychain Item." );
}
else
{
// No previous item found; add the new item.
// The new value was added to the keychainData dictionary in the mySetObject routine,
// and the other values were added to the keychainData dictionary previously.

// No pointer to the newly-added items is needed, so pass NULL for the second parameter:
//NSAssert(SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainData],
// NULL) == noErr, @"Couldn't add the Keychain Item." );
NSLog(@"%ld", SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainData],NULL));
NSLog(@"%ld", SecItemDelete((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainData]));
}

}

为了调试,我注释了 NSAssert 并添加了 3 个 NSLog。
但是,我得到了错误:

-25299(errSecDuplicateItem, The item already exists.)



SecItemAdd 和

-25300(errSecItemNotFound, The item cannot be found.)



SecItemDelete

如何删除设备中的旧钥匙串(keychain)项?

最佳答案

我通过 SecItemDelete 删除旧的钥匙串(keychain)项。

   NSMutableDictionary* yourKeychainDictionary;
OSStatus status = SecItemDelete((CFDictionaryRef)yourKeychainDictionary);

关于ios - iOS的钥匙串(keychain)服务,删除钥匙串(keychain)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5813282/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com