Keychain Query Always Returns errSecItemNotFound After Upgrading to iOS 13

前端 未结 5 1262
春和景丽
春和景丽 2021-01-31 09:01

I am storing passwords into the iOS keychain and later retrieving them to implement a \"remember me\" (auto-login) feature on my app.

I implemented my own wrapper aroun

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 09:25

    I've had a similar issue where I was getting errSecItemNotFound with any Keychain-related action but only on a simulator. On real device it was perfect, I've tested with latest Xcodes (beta, GM, stable) on different simulators and the ones that were giving me a hard time were iOS 13 ones.

    The problem was that I was using kSecClassKey in query attribute kSecClass, but without the 'required' values (see what classes go with which values here) for generating a primary key:

    • kSecAttrApplicationLabel
    • kSecAttrApplicationTag
    • kSecAttrKeyType
    • kSecAttrKeySizeInBits
    • kSecAttrEffectiveKeySize

    And what helped was to pick kSecClassGenericPassword for kSecClass and provide the 'required' values for generating a primary key:

    • kSecAttrAccount
    • kSecAttrService

    See here on more about kSecClass types and what other attributes should go with them.

    I came to this conclusion by starting a new iOS 13 project and copying over the Keychain wrapper that was used in our app, as expected that did not work so I've found this lovely guide on using keychain here and tried out their wrapper which no surprise worked, and then went line by line comparing my implementation with theirs.

    This issue already reported in radar: http://openradar.appspot.com/7251207

    Hope this helps.

提交回复
热议问题