2

我最近安装了 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." );

听到错误 -25300 ( errSecItemNotFound )

我在我的权利文件中指定了钥匙串访问组。此错误仅发生在 iOS 7.1 模拟器中,而不发生在发生在真正的 iPhone 或 7.0 模拟器中。

有谁知道 Keychain 在 7.1 中发生了什么变化?

4

2 回答 2

5

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

话虽如此,我曾经有很多错误,但不是这个。基本上发生的事情是在保存它时检查您的项目是否已经在钥匙串中,以便添加它或只是更新它。在这里,即使项目完全不同,检查也会返回 true,因此它无法更新,因为 SecItemUpdate 认为它不存在。

你应该做的是重置你的钥匙串,你有两个选择:

  • 在模拟器上 Menu Simulator->Reset content and settings

  • 在代码中的某处运行此代码段:

基于此处的 Vegard 回答重置 iPhone 应用程序的钥匙串

-(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);
}
于 2014-03-12T09:11:46.697 回答
2

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

如果您在真实设备上运行您的应用程序,崩溃将消失。

于 2014-03-11T19:15:23.307 回答