Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Keychain Data will persist after app deleted and reinstall?

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.

like image 825
Emre Gürses Avatar asked Mar 02 '20 09:03

Emre Gürses


1 Answers

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.

like image 128
Andrew Z. Avatar answered Sep 28 '22 04:09

Andrew Z.