如何通过 iCloud 同步钥匙串

How to sync keychain over iCloud

我不想在钥匙串中存储我的应用程序的敏感数据。我还希望使用 iCloud 在设备间同步。

根据 Apple 的说法,这是可能的:

Does iCloud Keychain work with third-party apps?

Yes. Developers can update their apps to work with iCloud Keychain. Passwords saved by those apps are kept up to date on all devices that use the app and are using iOS 7.0.3 or later or OS X Mavericks v10.9 or later.

但是,我找不到关于应用程序所需内容的任何文档。如果用户启用了 iCloud 钥匙串,是否会同步钥匙串的所有内容?

添加任何要同步的项目时,您需要设置 kSecAttrSynchronizable 属性。我建议使用包装器库,例如 KeychainAccess (in swift) or UICKeyChainStore(在 Obj-C 中),因为它在很大程度上促进了钥匙串和各种属性的处理(它们都提供了 synchronizable 属性 )