I am working on an app that stores a password in the keychain. Everything is working fine when I run the app from Xcode using a development profile - I can save a password, quit the app, relaunch and fetch the password from the keychain.

However, whenever I run the app using an Ad Hoc or App Store profile SecItemCopyMatching always returns errSecItemNotFound when I try to fetch the password from the keychain after relaunching the app.

Is there something I missing with the app ID, provisioning profile or entitlements?

有帮助吗?

解决方案

Turns out I was being caught out by the Enable Foundation Assertions build setting. It seems to be set to No by default for release builds.

I was using code from Keychain Services Tasks for iOS in the Apple Docs which has a lot of the keychain calls (including SecItemAdd) wrapped in NSAssert() therefore they weren't getting called and nothing was getting saved to the keychain.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top