在 iPhone 应用程序开发中,如何将数据存储到文本文件中并在应用程序再次启动时检索它?
首先我想说,作为一名 iPhone 应用程序开发人员,我是个新手。所以请帮助我。现在,我的问题是,我想在我的 iPhone 应用程序中创建一个文本文件。如果我解释一下,我会说...
当用户登录我的应用程序时,他/她将提供用户名和密码,现在我想要将这些数据存储在文本文件中,文本文件将存储在 documentsDirectory
中,当该用户再次启动应用程序时,如果他/她不这样做,他将能够自动访问该应用程序,而无需进行任何身份验证检查第一次从应用程序注销。
1) 第一个人 -->登录 [用户名和密码]密码]-->存储用户名并传递到文本文件,因为新用户 -->享受应用程序-->注销。
2) 第二人 -->登录 [用户名和密码]密码]-->存储在文本文件中,因为新用户 -->享受应用-->没有注销。
3) 又是第二个人--->不会直接提供用户名和密码,他/她必须使用该应用程序 --> 注销。
4) 现在第一个人--->登录 [用户名和密码]密码]并通过保存的读取文本文件进行检查--->享受应用-->注销。
5) 现在第二个人 --->登录 [用户名和密码]密码]并通过保存的读取文本文件进行检查--->享受应用-->注销。
现在,我的问题是我该如何完成这个完整的过程。我可以使用 NSUserDefaults standardUserDefualts 来完成此操作吗?或者我需要创建一个文本文件来存储用户名和用户名。密码??
At first of all i want to say that i am newer as an iPhone application developer.So please help me. Now, My problem is, I want to make a text file in my iPhone app.If I explain it then I will say that...
When user will login in my app then he/she will give username and password, Now i want to store these data in the text file and text file will store in the documentsDirectory
, when this user again lunch the application then automatically he will able to excess the app without any authentication checking if he/she does not logout from the application first time.
1) 1st person --> login [username & password] --> store username and pass into text file because new user --> enjoy application -->logout.
2) 2nd person --> login [username & password] --> store in text file into text file because new user --> enjoy application --> did not logout.
3) 2nd person again ---> will not give username and password directly he/she have to use the application -->logout.
4) 1st person now ---> login [username & password] and check by saved reading text file ---> enjoy application --> logout.
5) 2nd person now ---> login [username & password] and check by saved reading text file ---> enjoy application --> logout.
Now, my question is how can i do this full process.Can i do this using NSUserDefaults standardUserDefualts
or i need to make a text file for storing username & password??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以在 standardUserDefaults 中存储像这样的简单数据。
我假设您会检查用户身份。
例如,如果用户 1 登录但没有注销,然后用户 2 启动应用程序会怎样?
就我个人而言,如果您计划让多个人在特定设备上访问该应用程序,并且每次都需要密码,我只会存储用户名。
设置:
获取:
Yes you can store simple bits of data like these in standardUserDefaults.
I assume that you will check user identity though.
e.g.what if user 1 logs in but does not logout and then user2 launches the app?
Personally I would only store the username if you plan for more than one person to access the app on a specific device and I would require the password each time.
set:
get:
我会考虑将用户名/密码存储在钥匙串中。它更安全,您不必担心该信息会从用户默认 plist 中被窃取。如果您仍想使用用户名和密码,请考虑在存储之前对其进行哈希处理。然后,如果该信息泄露出去(不太可能,但仍有可能),那么对他们来说就没有任何意义。
您实际上可以从管理器中查看用户默认值的内容,该信息只是以纯文本形式存储在那里,因此不建议使用它作为存储用户名和密码的方式。
I would think about storing username/password in the keychain. It is more secure and you won't have to worry about that information getting hacked out of the user defaults plist. If you still want to use a username and password, consider hashing it before storing it. Then if that information gets out (unlikely, but still possible) it won't mean anything to them.
You can actually view the contents of your user defaults from Organizer, the information is just stored as plain text there, so it is not recommended to use this as a way to store username and password.