0

What is the best way to keep a session on an iPhone app? I want something similar to this:

  • when I Log in the app must store the person that name of the person that logged in
    • when I Log out that session will be destroyed without no possibility to enter the app beside logging in again
    • when the app is put in background the session must be kept
    • when the app closes the session must be destroyed and the user must log in again when he opens the app

How can I store the session on the phone and have this functionality's? The login is made using CoreData and the databases are stored on iCloud.

Bogdan
  • 402
  • 2
  • 8
  • 18
  • As I know NSUserDefaults will solve your problem . After login just store those values using NSUserDefaults and after logout clear those values from NSUserDefaults . – Tendulkar Jun 11 '13 at 11:22
  • if the app closes will the User Defaults be deleted? I don't want the session to be kept if the app was closed – Bogdan Jun 11 '13 at 11:29
  • No , the session will be there . If you dont want to kept the session then why don't you take the variables in the appdelegate . So that once the app closes the variable will be reset . – Tendulkar Jun 11 '13 at 11:31
  • I'll try using a delegate thank you. – Bogdan Jun 11 '13 at 11:39

1 Answers1

0

It is better to user the keychain to store user name and password. You can use NSUserDefaults but it would not be secure. If you are using NSUserDefaults then store password in encrypted form.

keychain is more secure than NSUserDefaults.

This Stack Overflow link may help you.

Community
  • 1
  • 1
user1548843
  • 670
  • 12
  • 20