[英]How can I implement a “first time user registration” workflow in my Cocoa Touch app?
I'm implementing a "new user registration" in my app 我正在我的应用程序中实现“新用户注册”
The first time the user logs in, I'd like to have them complete a 4-step registration process to create their username, set their profile photo, etc.. Each step would be a different screen. 用户首次登录时,我想让他们完成一个4步骤的注册过程,以创建其用户名,设置其个人资料照片等。每个步骤将是一个不同的屏幕。
All this needs to be done just once. 所有这些只需完成一次。 I was wondering - 我在想 -
What is the best setup for these 4 screens? 这四个屏幕的最佳设置是什么? Should they be a UINavigationController
so that they are implemented as a "stack"? 它们应该是UINavigationController
以便将其实现为“堆栈”吗? ie the user can go back to the previous screens? 即用户可以返回到先前的屏幕?
How do I preserve the state of the registration? 如何保存注册状态? I'd like to know what step the user was on in case they leave halfway, or in general know whether I should display the registration (ie if this is their first time). 我想知道用户中途离开时要走的路,或者一般来说我是否应该显示注册信息(即这是否是他们的第一次)。 Is there a way I can store the number of steps completed, so that if numStepsCompleted == 0
then I know they haven't started and if numStepsCompleted < 4
I know they have started but not finished? 有没有一种方法可以存储已完成的步骤数,因此,如果numStepsCompleted == 0
那么我知道它们尚未启动,如果numStepsCompleted < 4
我知道它们已经启动但尚未完成?
In general, if there are any code examples online that implement something like this, it would be great to look at. 通常,如果在线上有任何代码示例实现了这样的功能,那么最好看一下。
Thanks! 谢谢!
I would present a UINavigationController modally from you root view controller. 我将从您的根视图控制器模态地呈现一个UINavigationController。 One the user has finished you can do 2 things: 用户完成一项操作后,您可以做两件事:
For the first point to can do something like that 首先要做这样的事情
+ (BOOL)isFirstTime{
static BOOL flag = NO;
static BOOL result;
if(!flag){
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasBeenLaunchedOnce"])
{
result = NO;
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasBeenLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
result = YES;
}
flag = YES;
}
return result;
}
If this is the very first launch, show registration/login process, if not go along by taking username and password from keychain. 如果这是第一次启动,请显示注册/登录过程,如果不是,则从钥匙串中获取用户名和密码。
Save a value in NSUserDefaults to know which is the last completed step done by the user. 在NSUserDefaults中保存一个值,以了解哪个是用户完成的最后一步。 As tou said, make a UINavigation to setup the four registration steps. 正如头说的那样,进行UINavigation来设置四个注册步骤。 When the app opens read the user defaults to know if the registration is finished. 当应用打开时,用户默认会知道注册是否完成。
There are a couple of different ways to implements this: 有两种不同的方法可以实现此目的:
1. Use a UINavigationController
1.使用UINavigationController
2. Use a UIPageViewController
(which I like better) 2.使用UIPageViewController
(我更喜欢)
3. Use a UITableView
to contain all the information in one screen 3.使用UITableView
在一个屏幕中包含所有信息
To keep track of the registration info you should implement a RegistraionInfo
class (or struct in Swift). 为了跟踪注册信息,您应该实现RegistraionInfo
类(或Swift中的struct)。 Since there should only be one instance of it, you can create a singleton and access it from anywhere - RegistrationInfo.sharedInstance()
由于应该只有一个实例,因此您可以创建一个单例并从任何地方访问它RegistrationInfo.sharedInstance()
You can also create an instance in the first ViewController and pass it to the next one on prepareForSegue:
. 您还可以在第一个ViewController中创建一个实例,并将其传递给prepareForSegue:
上的下一个实例。
The last part is to identify if the user already completed the Sign Up process. 最后一部分是确定用户是否已经完成了注册过程。 If you're using a Username/Password model then you should keep that info in the keychain and fetch it on launch. 如果您使用的是用户名/密码模型,则应将该信息保留在钥匙串中,并在启动时获取。
Otherwise you can keep a value in NSUserDefaults
. 否则,您可以在NSUserDefaults
保留一个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.