Our app is using the iOS Keychain to store secure information and setting the kSecAttrSynchronizable option so the values are accessible across devices (I’m also using Keychain Access on my Mac for testing). Everything works great - keys are synced between iOS devices and my Mac (all signed into the same iCloud account). However… if I restart a test device (let’s call it Thing1) the app on that device no longer plays well with the iCloud Keychain. If I add a key/value pair on Thing1, it does not show-up on the other devices and if I add a key/value pair on another device it’s not available on Thing1.
All devices are signed into same iCloud account and the Keychain option is enabled. If I switch OFF the Keychain option under iCloud on Thing1 and then switch it back ON (and sign-in)… they keys that were previously added on Thing1 become available on other devices after about a minute. From this point forward all’s well with Thing1 until it’s turned off again.
Uninstalling and reistalling the app after the device restart doesn't fix the issue - only turning iCloud Keychain off then back on works.
Devices are all at the latest production level OS (currently iOS 9.2.1).
We develop our apps using Xamarin (C# + .NET) so I’ll post the code snippet from a Swift test app I cobbled together. I even tried using the kishikawakatsumi KeychainAccess Swift library and still have the same behavior.
let value = "My Value"
var valueData: NSData?
valueData = value.dataUsingEncoding(NSUTF8StringEncoding,
allowLossyConversion: false)
let secItem: NSDictionary = [
kSecClass as String : kSecClassGenericPassword as String,
kSecAttrService as String : "com.foobar.KeychainSyncTest",
kSecAttrAccount as String : "test",
kSecValueData as String : valueData!,
kSecAttrSynchronizable as String : kCFBooleanTrue
]
let status = Int(SecItemAdd(secItem, nil))Super simple, so I’m not sure what I could be doing wrong.