简体   繁体   English

如何在一个iOS应用程序的单个实例上管理多个“登录”?

[英]How to manage multiple “logins” on a single instance of an iOS app?

I found this question: 我发现了这个问题:

What are the best practices for managing multiple users on an iPad app? 在iPad应用程序上管理多个用户的最佳实践是什么?

But it is a couple of years old, is answered by the asker and he doesn't seem to be too sure of himself, so I thought I'd go ahead and ask this: 但这才几岁,被问问者回答,他似乎不太确定自己,所以我想我继续问一下:

Say I'm making an app for tutors, that they use to track data of their students. 假设我正在为导师制作一个应用,他们可以使用该应用来跟踪学生的数据。 I want the tutor to be able to "login" with the name/ID of a particular student, so only that student's data is shown, and any new data is added to that student's data. 我希望导师能够使用特定学生的名称/ ID“登录”,以便仅显示该学生的数据,并将任何新数据添加到该学生的数据中。 This is throughout quite a wide ranging app. 这是一个相当广泛的应用程序。

I put "login" in inverted commas, because it is not really a login in the usual sense, as the app is only used by the one tutor. 我将“登录”用逗号分隔,因为按通常的意义它实际上不是登录,因为该应用程序仅由一位教师使用。

The "login" doesn't need security, and I won't even have passwords. “登录”不需要安全性,我什至没有密码。

I just want to know what the accepted way to tackle this is. 我只想知道解决这个问题的可接受方法。 Core Data? 核心数据? Keychain? 钥匙扣? User defaults? 用户默认值? Something else? 还有吗

I also need to be able to store what student is currently "logged in", and use this info throughout the app. 我还需要能够存储当前正在“登录”的学生,并在整个应用程序中使用此信息。 I'm thinking of using the singleton pattern. 我正在考虑使用单例模式。 Would that be the normal way to go? 那是正常的做法吗?

I'm a relatively newbie, having recently completed the Stanford beginners course. 我是新手,最近刚完成斯坦福大学的初学者课程。 I'm keen to make my app in a way that adheres to iOS standards. 我渴望以符合iOS标准的方式制作我的应用。

Thanks in advance. 提前致谢。

Use any database, such as SQL or CoreData. 使用任何数据库,例如SQL或CoreData。 Then make sure each entry in the database has an username property so you can later filter by it. 然后,确保数据库中的每个条目都有一个username属性,以便以后可以对其进行过滤。 To store the current user, I recommend NSUserDefaults . 要存储当前用户,我建议使用NSUserDefaults See the following links: 请参阅以下链接:

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html

https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/CoreData/cdProgrammingGuide.html https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/CoreData/cdProgrammingGuide.html

http://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app http://www.raywenderlich.com/913/sqlite-tutorial-for-ios-making-our-app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM