jrendel / SwiftKeychainWrapper

A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.
MIT License
1.59k stars 340 forks source link

Items still in Keychain after removal #98

Closed rjong closed 7 years ago

rjong commented 7 years ago

Hi there,

When my app sets some values in the Keychain with your library, it is still there even after deleting the app. You can test this by install the app, save some values, delete the app and install it again.

Is there a way to delete the values when the app is deleted?

Thanks.

Shermanaters commented 7 years ago

@rjong Values that you stored into the keychain will remain there unless you remove them by code or reset and remove all the data in the phone. If you want them to be deleted when deleting the app, you probably want to store them somewhere else.

rjong commented 7 years ago

Allright, thanks for the answer.

RishabhTayal commented 6 years ago

@rjong As a workaround, you could have a flag in Userdefaults which will track if the app launch is from fresh install or not. If it's a fresh install, you can manually delete the keychain items.

RishabhTayal commented 6 years ago

Something like this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        if !UserDefaults.standard.bool(forKey: "firstTimeLaunchOccurred") {
            KeychainWrapper.standard.removeAllKeys()
            UserDefaults.standard.set(true, forKey: "firstTimeLaunchOccurred")
        }

        return true
}
bialabs commented 2 years ago

Something like this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        if !UserDefaults.standard.bool(forKey: "firstTimeLaunchOccurred") {
            KeychainWrapper.standard.removeAllKeys()
            UserDefaults.standard.set(true, forKey: "firstTimeLaunchOccurred")
        }

        return true
}

Tried but removeAllKeys() returns false and Keychain is not cleared Any suggestions?