Search code examples
ioscocoa-touchsettingsnsuserdefaultsnsdata

Saving app settings - iOS


I have an iOS app which loads certain features depending on the settings that the user sets. Currently I am using NSUseDefaults to save and retrieve these settings and it works fine. But from what I understand anyone can view and edit them with a simple XML editor. You don't even need to jailbreak an iOS device to gain access to them. So they arn't very secure.

I was wandering if anyone could give me some advice on how I can go about saving app settings (these are NONE secure settings, no passwords, just simple things like ints and strings).

Here are a few ideas I had:

IDEA 1 Add a JSON file to the app NSBundle and then edit/save that JSON file every time you want to load/change the app settings.

IDEA 2 Use Keychain - it can store strings right? And it can't be accessed or edited by anyone. (hopefully even the NSA... lol). I could just store an array of strings in keychain for my app settings.

IDEA 3 Store the settings on a server and get the app to pull them down for the user every time they use the app.

IDEA 4 If NSUserDefaults supports this, then maybe locking the NSUserDefaults so that the end user can only view them but not edit them. Only the app will be able to edit them.

The main point is that I am worried that if I use NSUSerDefaults, the user may see them and edit them and then the app will not function properly. While I am not storing any kind of secure data, it would be nice if I can prevent the user from editing the app settings.

Are any of these approaches any good?

Thanks for your time, Dan.


Solution

  • All of them are good ideas, but just one issue with the first one: You can not write or change files in the main bundle.

    As long a the sure did not jailbreak their device the NSUserDefault can not easily be changed.

    The keychain should only be used for password, token, etc..

    In you case the NSUserDefault will do just fine, or just save the some file the documents directory of your is also an option. You can even create you now settings class that conforms the to NSCoding protocol and you can save it.