一个登录视图,注册或登录

时间:2013-08-24 22:40:17

标签: iphone ios login parse-platform

我希望能够只有一个登录屏幕。用户每次登录时都会输入用户名,电子邮件和密码。我有问题,我注册,注销,然后尝试使用相同的凭据登录,我只是得到一个错误,说用户名已被采取。如果他们给我正确的凭据,我该如何登录呢?

PFUser *user  = [PFUser user];
user.email = emailEntry;
user.username = nickNameEntry;
user.password = passwordEntry;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
    if (!error)
    {
        [MYAlertView showAlertWithTitle:@"Successful login"
                                 message:@"success"
                       cancelButtonTitle:@"OK"];
    }
    else
    {
        NSString *errorString = [[error userInfo] objectForKey:@"error"];
        [MyAlertView showAlertWithTitle:@"There was an error signing up."
                                 message:errorString
                       cancelButtonTitle:@"OK"];
    }
}];

1 个答案:

答案 0 :(得分:0)

如果用户需要注册(第一次),则需要使用–signUpInBackgroundWithBlock:,正如您所做的那样。

但是,如果他已经注册,我猜你应该使用+logInWithUsernameInBackground:password:block:

我从this page获得此信息,但是,我从未使用此SDK。

更简单的方法是:

  1. 有两个按钮,用于推送不同的视图控制器,一个用于注册,另一个用于登录
  2. 相同的表单和两个按钮,一个调用调用–signUpInBackgroundWithBlock:的方法,另一个调用+logInWithUsernameInBackground:password:block:
  3. 使用第二种解决方案时,问题是如果您使用相同的表格,则无法在注册时询问特殊信息(姓名,出生日期等)。

    编辑: 您可能想看一下:

    1. PFSignUpViewControllerDelegate
    2. PFLoginViewControllerDelegate
    3. Parse API Documentation(我在上面找到了两个链接)。