在 swift 和 IOS 10 崩溃中重置钥匙串

Reset Keychain in swift and IOS 10 crash

问题只发生在 Xcode 8 和 IOS 10。 如果我使用 XCode 8 和 IOS 9 它工作得很好。

func resetKeychain() {

    if !self.keychainItemData.isEmpty {
        let tempDict = self.dictToSecItemData(self.keychainItemData)
        var junk = noErr
        junk = SecItemDelete(tempDict as CFDictionary)

        assert(junk == noErr || junk == errSecItemNotFound, "Failed to delete current dict")
    }

    self.keychainItemData[kSecAttrAccount] = ""
    self.keychainItemData[kSecAttrLabel] = ""
    self.keychainItemData[kSecAttrDescription] = ""

    self.keychainItemData[kSecValueData] = ""
}

断言总是发生在 IOS 10 和应用程序崩溃

有什么想法吗?

在您的 Xcode 项目中,转到应用程序目标,然后转到功能。打开钥匙串共享。这应该可以解决问题![​​=10=]