开发者

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 t开发者_JS百科he user ends the app or click "logout".

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜