Been looking around to find a way to detect when an app is uninstalling/reinstalling. The thing is, I do not use NSUserDefaults, I use SwiftKeychainWrapper.
I need to clear that user's keychain when app uninstalls.
didFinishLaunchingWithOptions seems to call when app loads so no use there. Is there a way to detect a reinstall? I need to call this:
return KeychainWrapper.standard.removeObject(forKey: "myKey") // only when/if app is unsinstalled/reinstalling
Presumably you're using Keychain because you need to store sensitive information? If so then you could just store a boolean in UserDefaults and check if that exists. For example:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let freshInstall = !UserDefaults.standard.bool(forKey: "alreadyInstalled")
if freshInstall {
// delete your item from keychain
UserDefaults.standard.set(true, forKey: "alreadyInstalled")
}
return true
}
This way you still have the security of the Keychain, but the behaviour of UserDefaults on uninstall/reinstall.
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