我正在使用 KeychainItemWrapper 类来保存钥匙串中的数据,但是我的应用程序因崩溃日志而崩溃因未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:& #39;无法添加钥匙串项目。'
这是一种在钥匙串中写入数据的方法
- (void)writeToKeychain
{
NSDictionary *attributes = NULL;
NSMutableDictionary *updateItem = NULL;
OSStatus result;
if (SecItemCopyMatching((CFDictionaryRef)genericPasswordQuery, (CFTypeRef *)&attributes) == noErr)
{
// First we need the attributes from the Keychain.
updateItem = [NSMutableDictionary dictionaryWithDictionary:attributes];
// Second we need to add the appropriate search key/values.
[updateItem setObject:[genericPasswordQuery objectForKey:(id)kSecClass] forKey:(id)kSecClass];
// Lastly, we need to set up the updated attribute list being careful to remove the class.
NSMutableDictionary *tempCheck = [self dictionaryToSecItemFormat:keychainItemData];
[tempCheck removeObjectForKey:(id)kSecClass];
#if TARGET_IPHONE_SIMULATOR
// Remove the access group if running on the iPhone simulator.
//
// Apps that are built for the simulator aren't signed, so there's no keychain access group
// for the simulator to check. This means that all apps can see all keychain items when run
// on the simulator.
//
// If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the
// simulator will return -25243 (errSecNoAccessForItem).
//
// The access group attribute will be included in items returned by SecItemCopyMatching,
// which is why we need to remove it before updating the item.
[tempCheck removeObjectForKey:(id)kSecAttrAccessGroup];
#endif
// An implicit assumption is that you can only update a single item at a time.
result = SecItemUpdate((CFDictionaryRef)updateItem, (CFDictionaryRef)tempCheck);
NSAssert( result == noErr, @"Couldn't update the Keychain Item." );
}
else
{
// No previous item found; add the new one.
result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
}
}
我的应用正在崩溃
result = SecItemAdd((CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
断言错误消息断言失败 - [KeychainItemWrapper writeToKeychain]
以下是keychainItemData
中指定的值Printing description of self->keychainItemData:
{
acct = "";
desc = "";
gena = "com.xyz.abc";
labl = "";
"v_Data" = "ABCDSS-ABCDSS-ABCDSS-TEST-DATA";
}
我知道这里曾经多次询问过类似的问题,但没有任何帮助。
任何人都可以帮助我吗?是否还有其他方法可以在钥匙串中保存数据。
提前致谢。
答案 0 :(得分:-1)
在方法中使用self.keychainItemData而不是keychainItemData?
<android version="1.0" securityTest="AuthSecurityTest">