PassionateDeveloper
PassionateDeveloper

Reputation: 15138

iOS: How to save data over the complete lifecycle?

I have an iOS app with a login view.

I need to have the login-data the whole time until the user ends the app or click "logout".

How and where to store it? Are something equel like "member variables" possible in iOS / objective C?

Upvotes: 1

Views: 482

Answers (2)

JonasG
JonasG

Reputation: 9324

You could use NSUSerDefaults, but everything you save in NSUserDefaults stays there for ever unless you delete it. Id I understand i right, you want that the password ans login gets saved only when the app is opened, and when the app is being closed, that data gets deleted? With nsuserdefaults you will have to set @"" for the password and login in applicationwillterminate, to delete the data. Or you declare two NSStrings in you header file, and in the .m you do passwdstring = passwd.text loginstring = login.text

what this does is it saves the data to two nsstrings, that data is available the whole time while the app is opened, when the user closes the app, and re opens it, the strings are nil again and when he logs in, the strings will have the loging info again.

Upvotes: 0

csano
csano

Reputation: 13686

If you're going to be storing username/password data, it's probably best to store it in the keychain. If you're only looking to keep track of whether a user is logged in, then consider storing a flag of some kind in NSUserDefaults. You can clear data when the application exits through the applicationWillTerminate: method of your application delegate.

Upvotes: 3

Related Questions