I've been trying to solve this problem for days now. Currently I'm saving a user id and device id to keychain so if the user installs the app to another device, he/she can access the data from our backend without any problems.
I'm developing on an iPhone, and the second device is an iPad. When I first tested the synced keys, iPad loaded them as expected and everything worked fine. But then, syncing stopped when I started deleting or updating the keys.
Currently both devices are not able to get the updates from Apple.
I thought this was a framework issure. I was using KeychainSwift because it's apis are simpler. So I changed it to KeychainAccess. With both frameworks the state is the same, no syncing between devices. I returned back to KeychainSwift...
I tried disabling/enabling keychain for iCloud on both devices, logging out and in again, resetting and logging in. Nothing seems to work. I am unable to continue to progress on the app.
This is how I'm reading/writing with KeychainSwift:
static func write (key: SettingKey, value: String, syncronizable: Bool = true) -> Void {
let keychain = KeychainSwift()
keychain.accessGroup = Settings.accessGroup
keychain.synchronizable = syncronizable
keychain.set(value, forKey: key.rawValue, withAccess: .accessibleAfterFirstUnlock)
if keychain.lastResultCode != noErr {
let error = KeychainError(status: keychain.lastResultCode)
appSimple(" Keychain error for \"\(key.name())\" -> \(error.description)")
}
}
static func read (key: SettingKey, syncronizable: Bool = true) -> String? {
let keychain = KeychainSwift()
keychain.accessGroup = Settings.accessGroup
keychain.synchronizable = syncronizable
let value: String? = keychain.get(key.rawValue)
if keychain.lastResultCode != noErr {
let error = KeychainError(status: keychain.lastResultCode)
appSimple(" Keychain error for \"\(key.name())\" -> \(error.description)")
return nil
}
return value
}
is a string enum.SettingKey
is a static constants defined as string.Settings.accessGroup
is anKeychainError
enum, containing string descriptions for possible keychain error codes.OSError
is a debug printing method of my own.appLog
I'm currently stuck with this problem. Any help is appreciated. 😟