How persistent is [NSUserDefaults standardUserDefa

2020-03-01 17:44发布

问题:

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

回答1:

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.



回答2:

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.