3

I have an iOS application that uses the keychain to store some information related to the authentication. I would like to remove this data from the keychain when the application is uninstalled. How can I get aware of the application being uninstalled/removed?

Mihai Popa
  • 892
  • 1
  • 8
  • 25
  • 3
    possible duplicate of [Delete keychain items when an app is uninstalled](http://stackoverflow.com/questions/4747404/delete-keychain-items-when-an-app-is-uninstalled) – fifarunnerr Mar 05 '14 at 07:51

1 Answers1

5

You can´t detect when your application is going to be deleted from your device. But you could detect when your app is launched for first time, after to be installed. For this I use the next code:

if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunched"])
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunched"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    //Here delete your info kept in your keychain. If not exist will not delete nothing, but if it exist mean your app has been installed again.
    [removeYourPropertyInKeychain];
}
Fran Martin
  • 2,369
  • 22
  • 19