【问题标题】:KeychainWrapperItem stopped working in iOS 7.1KeychainWrapperItem 在 iOS 7.1 中停止工作
【发布时间】:2014-03-10 20:35:06
【问题描述】:

我最近安装了 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 中发生了什么变化?

【问题讨论】:

    标签: ios keychain keychainitemwrapper


    【解决方案1】:

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

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

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

    • 在模拟器上 Menu Simulator->重置内容和设置

    • 在代码中的某处运行这个 sn-p:

    基于 Vegard 的回答 Reset An iPhone App's Keychain

    -(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);
    }
    

    【讨论】:

    • 你很亲密。错误代码是 25300。我编辑了我的问题。你知道一个值得推荐的 Keychain Wrapper 吗?
    • SSKeychain 很受欢迎,而且使用简单。
    • 非常感谢。我认为重要的是要知道重置位置和隐私没有起作用。只有在使用代码 sn-p 删除所有键后,我现在才能运行我的应用程序。
    • 我确实更新了我的答案,它是通过重置模拟器菜单中可用的内容和设置,而不是模拟器本身。
    【解决方案2】:

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

    如果你在真机上运行你的应用,崩溃就会消失。

    【讨论】:

    • 确实如此。但是为什么会在 7.1 模拟器上崩溃?也可以在模拟器中运行我的应用程序。
    猜你喜欢
    • 1970-01-01
    • 2021-11-17
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多