[英]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. 我无法使用共享钥匙串在WatchKit和iPhone应用程序之间共享数据。 When I am trying to use
kSecAttrAccessible
as kSecAttrAccessibleAlways
in keychain wrapper, SecItemUpdate
failed. 当我在keychain包装器中尝试使用
kSecAttrAccessible
作为kSecAttrAccessibleAlways
时, SecItemUpdate
失败。 Please help me to use kSecAttrAccessible
in keychain wrapper properly. 请帮我正确使用钥匙串包装中的
kSecAttrAccessible
。
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. 默认的钥匙串模式
kSecAttrAccessibleWhenUnlocked
和kSecAttrAccessibleWhenUnlockedThisDeviceOnly
不会让您的应用程序扩展程序在iPhone被锁定时访问数据。
Therefore, use kSecAttrAccessibleAfterFirstUnlock
or kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
are appropriate in this case. 因此,在这种情况下使用
kSecAttrAccessibleAfterFirstUnlock
或kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
是合适的。 This allows the WatchKit extension to access the keychain even when the iOS app is in the background. 即使iOS应用程序在后台,这也允许WatchKit扩展程序访问钥匙串。
Old items (with kSecAttrAccessibleWhenUnlocked
) have to be re-saved (read, delete, save with new accessibility mode). 必须重新保存旧项目(使用
kSecAttrAccessibleWhenUnlocked
)(读取,删除,使用新的辅助功能模式保存)。
More information (including code) is available here , here , and here . 更多信息(包括代码)可在此处 , 此处和此处获得 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.