简体   繁体   中英

How to share keychain data between a WatchKit extension and an iPhone app

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM