Search code examples
ioskeychain

keychain stored password is still available after app re-installed


I am developing iOS app with xcode8+swift3.

I have created functions to store user password to keychain and read password out from keychain. You can refer to here for the functions I have created.

The problem I noticed in general is, even I uninstalled the app, when I re-install the app, my app read password from keychain is the old password from previously installed app (which has uninstalled already).

My question is, what is the best practice to address this issue?


Solution

  • In the app delegate you can do:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
       BOOL savedInKeychain = [[NSUserDefaults standardUserDefaults]boolForKey:@"savedInKeychain"];
       if(!savedInKeychain){
        //There is no keychian data saved in this app
        //check if data exisst in keychain
        if(kechainData){
            //Delete keychain data
        }
    
       return YES;
    }
    

    Later after you save data in keychain, set savedInKeychain to YES in userdefaults.