-
Notifications
You must be signed in to change notification settings - Fork 772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using KeychainAccess for saving UUID and store after reinstall app #192
Comments
I think that Keychain returns nil is very rare case. |
Ok, thanks for answer. My usage of KeychainAccess: func getUUID() -> String {
let userDefaults = NSUserDefaults.standardUserDefaults()
if let uuid = userDefaults.objectForKey(Constants.UserDefaults.UUID) as? String {
return uuid
} else {
let keychain = Keychain(service: Constants.Keychain.Service)
if let token = try? keychain.getString(Constants.Keychain.UUID) {
if let tkn = token {
userDefaults.setObject(token, forKey: Constants.UserDefaults.UUID)
return tkn
} else {
return self.generateNewUUID()
}
} else {
return self.generateNewUUID()
}
}
}
func generateNewUUID() -> String {
let userDefaults = NSUserDefaults.standardUserDefaults()
let keychain = Keychain(service: Constants.Keychain.Service)
let UUID = NSUUID().UUIDString
userDefaults.setObject(UUID, forKey: Constants.UserDefaults.UUID)
userDefaults.synchronize()
keychain[Constants.Keychain.UUID] = UUID
return UUID
} If it is okay you can close this. I am use it this way and for now without problem. |
Hi @LiborZ Did setting the synchronizable to false help prevent the Keychain from being shared among devices through iCloud? |
Nope. Is it enought to change in both methods code to:
or do I need to do more changes? Thanks |
Hi,
I am looking solution for have same ID for device even when user delete app and then install it again. I found that others are using keychain for this. But I've read about some problems that sometimes Keychain returns nil and the second problem could be that ID from keychain would be shared across devices and I really don't want that. I guess that when I set synchronizable to false that there shoudn't be second issue. But what about first one? Is it possible that sometimes Keychain returns nil even if there are saved data? For example link here: soffes/SAMKeychain#75 Should I combine this with NSUserDefaults? When app is launched for first time get ID from keychain and save it to NSUserDefaults for other needs. Thanks for help
The text was updated successfully, but these errors were encountered: