3

I have created an application which will login using username, password and allows the user to download the files from serve. In my application I have to persist few datas once the user have login in the application.

Persisting data like Username, Password, user downloaded list , subscribed plans,etc. The data can be persisted in application either by NSUserDefaults,Plist , etc. But I feel easy to store and retrieve the values using NSUserDefaults. As I need to use the values in many view controllers, I prefer NSUserDefaults.

Is this the best practice ? Using too much NSUserDefaults will result in a trap ? Tell me is there other way to persist the data and retrieve it easily in cocoa-touch ?

Raptor
  • 53,206
  • 45
  • 230
  • 366
Cyril
  • 1,216
  • 3
  • 19
  • 40

3 Answers3

2

You can use NSUserDefaults for storing user data.

But for highly sensitive data like Username and Password I prefer keychain to store them.

Please check these links for Keychain saving:

  1. Simple iphone keychain access
  2. saving email password to keychain in ios
  3. howto use keychain in iphone sdk
Community
  • 1
  • 1
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • Thank you. Let me check with Keychain API – Cyril Jan 23 '13 at 06:05
  • But can we use Keychain only for storing username and passwords OR we can use like key-value pair ? – Cyril Jan 23 '13 at 06:06
  • @Cyril: I added links, you can save in it like keyvalue pairs – Midhun MP Jan 23 '13 at 06:09
  • Thank you . Thats a lot of info you have provided to me. I will use it. please let me know, whether too much usage of NSUserDefaults will led to application crash ? – Cyril Jan 25 '13 at 06:36
  • @Cyril: No, But use it for only the user specific data. Never use it for storing data related to functionality if it can be stored to database – Midhun MP Jan 25 '13 at 07:54
2

In my opinion , if you want to store little data , such as username , password or some BOOLs , you can use NSUserDefaults .

As the NSUserDefaults is a common plist , if you want to store some your data such as your download links , it is better to use your custom plist .

If you want to store some big data such as UIImage , you can use NSCache , but it may evict data.

If you want to store a lot of data , it better to use database.

Guo Luchuan
  • 4,729
  • 25
  • 33
0

I would look into using a library such as https://github.com/kishikawakatsumi/UICKeyChainStore which is just a really nice wrapper around the ios keychain store and store sensitive data in the users keychain rather than the user defaults plist as it is more secure.

As for the data if its not secure there is no reason why you couldn't just write them out to files and load them back in?

Shaun
  • 412
  • 2
  • 7
  • Sorry, the details which am gonna sore should be more more secure – Cyril Jan 23 '13 at 06:04
  • Are you simply downloading files once which you then want to securely store ... or will they be downloaded every time the app is up and running? – Shaun Jan 23 '13 at 06:07
  • Making the downloaded data secure is not a problem for me , as the file which I am downloading is encrypted. I just want to store the datas securely used in application such as username,password, etc. – Cyril Jan 25 '13 at 06:34