KeychainWrapperItem在iOS 7.1中停止工作

KeychainWrapperItem在iOS 7.1中停止工作,ios,keychain,keychainitemwrapper,Ios,Keychain,Keychainitemwrapper,我最近安装了iOS 7.1模拟器和新的Xcode 5.1。我的应用程序在iOS 7中运行良好。我正在使用来自Apple的KeychainItemWrapper类。 更新后,它崩溃,并显示以下消息: *** Assertion failure in -[KeychainItemWrapper writeToKeychain] 特别是在第299行: NSAssert( result == noErr, @"Couldn't update the Keychain Item." ); 错误为hea

我最近安装了iOS 7.1模拟器和新的Xcode 5.1。我的应用程序在iOS 7中运行良好。我正在使用来自Apple的KeychainItemWrapper类。 更新后,它崩溃,并显示以下消息:

*** Assertion failure in -[KeychainItemWrapper writeToKeychain]
特别是在第299行:

NSAssert( result == noErr, @"Couldn't update the Keychain Item." );
错误为hear-25300(errSecItemNotFound)

我已在我的权限文件中指定了密钥链访问组。此错误仅在iOS 7.1模拟器中发生,而在真正的iPhone或7.0模拟器上未发生


有人知道7.1中的Keychain发生了什么变化吗?

Keychain在iOS 7.1下继续工作。您的问题与模拟器本身有关。据我所知,模拟器不允许存储某些密钥,这在iOS 7.0和iOS 7.1之间是一致的


如果你在真正的设备上运行你的应用程序,崩溃就会消失。

那么KeychainItemWrapper是一个充满bug的旧实现。我建议使用另一个包装器,或者编写自己的包装器

也就是说,我以前有很多错误,但这次没有。基本上,保存时会检查您的项目是否已经在密钥链中,以便添加它或只是更新它。在这里,即使项完全不同,检查仍返回true,因此无法更新,因为SecItemUpdate认为它不存在

您应该做的是重置钥匙链,您有两个选项:

  • 在simulator菜单simulator->重置内容和设置

  • 在代码中的某个位置运行此代码段:

基于这里的Vegard答案


你很接近。错误代码是25300。我编辑了我的问题。你知道推荐的钥匙链包装器吗?很受欢迎,而且使用简单。非常感谢。我认为重要的是要知道重置位置和隐私不起作用。只有在用代码片段删除所有键一次之后,我现在才能运行我的应用程序。我确实更新了我的答案,它是通过重置模拟器菜单中的内容和设置,而不是模拟器本身。这是真的。但是为什么它会在7.1模拟器上崩溃呢?在模拟器中运行我的应用程序也很好。
-(void)resetKeychain {
     [self deleteAllKeysForSecClass:kSecClassGenericPassword];
     [self deleteAllKeysForSecClass:kSecClassInternetPassword];
     [self deleteAllKeysForSecClass:kSecClassCertificate];
     [self deleteAllKeysForSecClass:kSecClassKey];
     [self deleteAllKeysForSecClass:kSecClassIdentity];
}

-(void)deleteAllKeysForSecClass:(CFTypeRef)secClass {
     NSMutableDictionary* dict = [NSMutableDictionary dictionary];
    [dict setObject:(__bridge id)secClass forKey:(__bridge id)kSecClass];
    OSStatus result = SecItemDelete((__bridge CFDictionaryRef) dict);
     NSAssert(result == noErr || result == errSecItemNotFound, @"Error deleting keychain data (%ld)", result);
}