As you know, getting a unique ID in iOS devices is banned by Apple. But sometimes we need to identify devices, for example, got bonus when the app first installed with the only once user. We don't want to sign(earn the bonus) multiple users in one device.
So, we got vendorID from the device and save this data on a keychain(vendorID changed the time by time, but we don't want to changingID). After that, we check this data is available on a keychain. I read this thread [iOS autodelete Keychain items after uninstall][1] that related keychain data will be removed after the app deleted.
But when I try this scenario. My keychain data don't delete and keychain data persistent after deleting.
So my question is raized from this point. Anyone know about this issue? After my app deleted, keychain data will be persisted or removed all keychain data.
Keychain data will delete after uninstall?
To look at my keychain data saving function.
class func getUniqueDeviceID() -> String {
guard let uniqueDeviceId = KeychainKeeper.shared.uniqueDeviceID else {
let deviceId = (UIDevice.current.identifierForVendor?.uuidString)~
KeychainKeeper.shared.uniqueDeviceID = deviceId
return deviceId
}
return uniqueDeviceId
}
Please do not offer other solutions. We are stuck in this scenario. We want to sure after the deleting app keychain will be deleting or not [1]: https://forums.developer.apple.com/thread/36442
ANSWER :
Keychain data always persist now.
Keychain data always persist now.
The auto-delete of keychain value was in a beta of 10.3, but for some reason, they removed this possibility. I guess to many applications get used to not droppable keychain.
Check this question.
There is a super simple way trough UserDefaults
:
func clearKeychainIfWillUnistall() {
let freshInstall = !UserDefaults.standard.bool(forKey: "alreadyInstalled")
if freshInstall {
KeychainKeeper.shared.clear()
UserDefaults.standard.set(true, forKey: "alreadyInstalled")
}
}
Call it in AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.clearKeychainIfWillUnistall()
}
The simplest workaround that I know. I hope it will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With