I am unable to share data between WatchKit and an iPhone app using a shared keychain. When I am trying to use kSecAttrAccessible
as kSecAttrAccessibleAlways
in keychain wrapper, SecItemUpdate
failed. Please help me to use kSecAttrAccessible
in keychain wrapper properly.
You should use the correct accessibility mode:
The default keychain modes kSecAttrAccessibleWhenUnlocked
and kSecAttrAccessibleWhenUnlockedThisDeviceOnly
will not let your app extension access data while the iPhone is locked.
Therefore, use kSecAttrAccessibleAfterFirstUnlock
or kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
are appropriate in this case. This allows the WatchKit extension to access the keychain even when the iOS app is in the background.
Old items (with kSecAttrAccessibleWhenUnlocked
) have to be re-saved (read, delete, save with new accessibility mode).
More information (including code) is available here, here, and here.