Search code examples
ioskeychain

Store item in iOS Keychain without iCloud sync?


I am developing an application in iOS where I need to store secure data in the keychain during registration of an account in the app.
The problem I am facing is that sometimes, when a user has a second device, their registration is (suspected) failing because this item already exists in the keychain due to sync'ing in iCloud. It could possibly be a case that the user has reinstalled the app and an item in keychain survived the reinstall, but unfortunately the only details given to me is 'the user can't register' with the log files, which complains about the keychain item.

Sadly, this registration process is set in stone as it is an inherited project that is already in production so I can't really change it too much.

My knee-jerk response is to somehow stop this item from sync'ing across devices, but I can't even seem to find anything that would suggest that this was possible.
All thoughts welcome
Thanks

Edit
I just realised that my question wasn't very clear. I guess it's a two-parter
1. Is there a way to stop keychain items from sync'ing with iCloud.
2. Can anyone think of a way around this, if not?


Solution

  • If you do not specify the kSecAttrSynchronizable attribute with a true value in the keychain item dictionary when you create the keychain item, then it will not be synchronised via iCloud; it will just remain on the localdevice.

    It is more likely that there is an old item in the keychain. You will need to examine the registration code and modify it to provide some method of recovering from a failed registration attempt.