保存用户名和密码组合
我有一个应用程序,要求用户输入我想要保存的用户名和密码(这样用户就不必在每次启动时重新输入他的数据)。 当然,我需要在下次应用程序启动时访问用户名和密码。你能告诉我该怎么做吗?
另一件事:用户名(和密码)保存在 AppDelegate 中,但稍后我需要在不同的类中使用它。
I have an app which asks the user for a username and password which I want to be saved (so the user doesn't have to reenter his data on every launch).
Of course I need to acces the username and password on the next application start. Can you tell me how to do it?
One more thing: the username (and pw) is saved in the AppDelegate but I need it in a different class later..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
保存用户名/密码的正确位置是钥匙串中。使用 SSKeychain 等开源包装器可以更轻松地实现这一点。
我怀疑您想要执行此操作的方式是使用 NSUserDefaults,您可以在 首选项和设置用户指南。
无论哪种方式,您都可以从应用程序的其他位置轻松获取信息。
但你确实应该用第一种方法。
尝试一下,如果无法让它发挥作用,请回来询问更具体的问题。
The proper place to keep a username/password is in the keychain. It's made easier with open source wrappers such as SSKeychain.
The way I suspect you want to do it is with NSUserDefaults, which you can read about in the Preferences and Settings User Guide.
Either way you can get at the information quite easily from elsewhere in your application.
But you really should do it the first way.
Give it a try and come back and ask a more specific question if you can't get it to work.