12

I have a problem . I am saving some critical information on device Keychain for my App, but when I uninstall the App and install it again, these data is still saved. How can delete these information when the application is uninstalled? If this is not possible, how detect when the App is first Load after install it without save information in NSUserDefaults?

Thank you very much.

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Paolpa
  • 319
  • 2
  • 5
  • 10
  • 1
    http://stackoverflow.com/q/4747404/653513 – Rok Jarc Jan 03 '14 at 12:57
  • 2
    Why don't you want to use NSUserDefaults to store whether or not your application is started for the first time? – tilo Jan 03 '14 at 13:00
  • you cannot do anything when the application is removed from the device, the application won't be notified about that event. – holex Jan 03 '14 at 13:03
  • Because I am saving critical information and I don't want that someone can edit the preferences plist with any program as iExplorer. If someone change any value the consequences could be very bad – Paolpa Jan 03 '14 at 13:04
  • @Paolpa, in that case, you should use some encryption then... e.g. _AES256_ is good enough to protect your critical information. – holex Jan 03 '14 at 13:06
  • Theoretically keychain is safe enough, right? – Paolpa Jan 03 '14 at 13:09
  • 1
    @Paolpa, you problem is here not the safety, your original problem was about you want to delete information when the application is deleted/uninstalled; which is not possible. – holex Jan 03 '14 at 13:18

2 Answers2

5

This is work around , but may be will satisfy you: Store in NSUserDefaults flag, that keychain have data. If it's NO then ignore keychain.

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Cy-4AH
  • 4,370
  • 2
  • 15
  • 22
  • 3
    You should not use NSUserDefaults for sensitive data like passwords or certificates. – orkoden Mar 03 '14 at 13:41
  • 1
    @orkoden, anybody have said about storing passwords in NSUserDefaults? I am not. – Cy-4AH Mar 03 '14 at 13:46
  • @ta.speot.is, Have you minused answer in http://stackoverflow.com/questions/4747404/delete-keychain-items-when-an-app-is-uninstalled? It's the same, but shorter. – Cy-4AH Oct 30 '14 at 10:23
  • Sorry, I misread your answer. I can't take back my downvote because I downvoted you a few hours ago, but if you make a small edit to your answer I can upvote it. – ta.speot.is Oct 30 '14 at 10:26
  • I disagree to save critical information in UserDefaults. – Zhou Haibo Aug 09 '21 at 06:57
0

I'm not sure why you would not want to use NSUserDefaults. It seems ideal for this purpose.

Barring NSUserDefaults, you could write a file to the Documents directory and use the existence of this file as your flag.


I think I misunderstood your question. I assume the whole time you would use the keychain to store the secure value.

Use a flag in NSUserDefaults to signal that you need to delete the keychain on first launch.


As a real alternative to Keychain, use the Data Protection entitlement.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117