9

I'm using [NSUserDefaults standardUserDefaults] for storing application settings.

My questions are:

  • do those settings are removed on app deletion?
  • are they kept after an application update (through the AppStore)?

Because I'm using it to store a password and don't want my users to reset them at each update. Also, I'd like that the only way to reset the password would be to remove the app and re-install it.

Is NSUserDefault the right choice?

Thanks, Jérémy

jchatard
  • 1,881
  • 2
  • 20
  • 25

2 Answers2

22

Yes, they are removed on app deletion and yes they are kept when an application is updated.

However, you're not advised to store sensitive data in the NSUserDefaults, instead I would look at using the Keychain.

Tom Irving
  • 10,041
  • 6
  • 47
  • 63
  • 1
    Thank you Tom! Exactly the kind of response I needed. – jchatard Jun 28 '10 at 15:34
  • Hi Tom and jchatard, thanks for your post, it helps me also. However if I want to store the data even when the app is deleted, is there anyway? Like using plist? My situation is to store the info of whether the user has in-app purchased items. Obviously I don't want to charge them again if they remove and reinstall the app. Or is it done by the app store to remember their purchase history at their iTunes account? Thanks. – Anthony Jun 29 '10 at 00:57
  • When an app is deleted, ALL its data is deleted along with it. I don't know whether or not the store remembers what a user has purchased. – Tom Irving Jun 29 '10 at 16:53
  • the only way is to use cloud storage, this would also allow you to 'sync' preferences between multiple devices running your app – Ronny Webers Mar 26 '14 at 19:22
  • @Anthony `SKPayment.defaultQueue().restoreCompletedTransactions()` will work. – return true Dec 30 '15 at 12:22
  • @TomIrving Not so. Information regarding an app's push notifications (permissions and badge count) are persisted until 24 hours after app uninstallation. http://stackoverflow.com/a/4080720/64505 – funkybro Jan 12 '16 at 14:46
0

I use NSUserDefaults in my app to allow additional access to my app for my colleagues. They just have to enter the code word in settings and the app is fully opened.

to the point each time I update the app they have to re-enter the code word, so I would say from experience that they are not kept after updates. The values need to be re-entered.

RyanTCB
  • 7,400
  • 5
  • 42
  • 62