简体   繁体   English

如何在WatchKit扩展和iPhone应用程序之间共享钥匙串数据

[英]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. 默认的钥匙串模式kSecAttrAccessibleWhenUnlockedkSecAttrAccessibleWhenUnlockedThisDeviceOnly不会让您的应用程序扩展程序在iPhone被锁定时访问数据。

Therefore, use kSecAttrAccessibleAfterFirstUnlock or kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly are appropriate in this case. 因此,在这种情况下使用kSecAttrAccessibleAfterFirstUnlockkSecAttrAccessibleAfterFirstUnlockThisDeviceOnly是合适的。 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.

相关问题 在iOS App和WatchKit Extension之间共享Plist - Share Plist between iOS App and WatchKit Extension 如何使watchkit扩展应用程序和我的iPhone应用程序共享相同的icloud数据库 - how to make watchkit extension app and my iphone app share the same icloud databases Watchkit和iphone app之间没有共享数据 - Data is not getting shared between watchkit and iphone app 使用钥匙串在 iOS 扩展程序及其包含的应用程序之间共享? - Share between an iOS extension and its containing app with the keychain? 如何在iPhone应用程序和applewatch之间共享数据? - How to Share data between iPhone app and applewatch? Appcelerator iOS 应用程序:如何从共享扩展中读取钥匙串值? - Appcelerator iOS app: how to read Keychain value from Share Extension? 如何通过存储“回复”块在iOS应用和WatchKit扩展之间进行通信? - How to communicate between an iOS app and the WatchKit extension by storing the “reply” block? iOS - WatchKit如何将消息/数据从iPhone应用程序发送到WatchKit应用程序? - iOS - WatchKit how to send message/data from iPhone app to WatchKit app? 如何在 iOS 中的扩展和主机应用程序之间共享后删除数据 - How to remove data after share between extension and host app in iOS WatchKit扩展:如何从主机iOS应用读取数据? - WatchKit extension: how to read data from host iOS app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM