我在注册视图控制器中实现了以下功能(附加到“注册按钮”),如下所示。该函数依赖于Parse,并且通常是无缝的。
但是我目前遇到以下问题:
如果用户错误地插入了无效的电子邮件地址; “else”下列出的错误字符串被激活(这很好),但无论如何都会注册上面输入的用户名和密码。
用户可以将密码字段留空。
任何帮助,尤其是与第1期有关的任何帮助,都会受到极大的赞赏。
// Register user.
- (IBAction)registerUser:(id)sender
{
PFUser *user = [PFUser user];
user.username = self.mobileTextField.text;
user.password = self.passwordTextField.text;
user.email = self.emailTextField.text;
// Show loading HUD.
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{
[self performSegueWithIdentifier:@"userRegistered" sender:self];
}
else
{
NSString *errorString = [[error userInfo] objectForKey:@"error"];
UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[errorAlertView show];
// Dismiss loading HUD.
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
});
}
}];
// End editing.
[self.view endEditing: YES];
});
}
答案 0 :(得分:1)
这里有很多问题。
a,你绝对不需要也不应该采取新的主题。 Parse会为你做这件事。你必须改变它。
b,你可能正在寻找解析中的神奇公式“如果((!成功)||错误)......”
c,在发送电子邮件之前,您应该本地检查该电子邮件是否有效。 (即,您不能输入“xyz @ hotmail”或不合理的电子邮件。)
即,您需要编写一个例如“checkThisEmailIsValid”的例程。如果你需要帮助他的大喊大叫。请注意,从概念上讲,这并不容易。您了解解析会尝试验证电子邮件吗?即它会发送其中一封电子邮件“新用户,点击此处验证您的电子邮件!”你对此很熟悉吗?
d,一个很大的秘密是202错误代码
这是来自制作应用程序的一些示例代码,希望它有所帮助!
-(void)_actuallyJoin
{
... do things like check the email is valid
... in this app the username is the lowercase email
PFUser *nuser = [PFUser user];
nuser.username = [self.email.text lowercaseString];
... in this app, the email is the email, password is the password
nuser.email = self.email.text;
nuser.password = self.password.text;
[APP huddie];
APP.hud.labelText = @"Registering ...";
APP.hud.detailsLabelText = @"1 of 3 ...";
... that is just MBProgressHUD.
[nuser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if ( (!succeeded) || error)
{
[APP.hud hide:YES]; .. that's MBProgressHUD
.. usually, blank the form while app is connecting
self.email.text = @"";
self.password.text = @"";
self.confirmPassword.text = @"";
if ( error.code == 202 )
{
[PFAnalytics trackEvent:@"newAccount"
dimensions:@{ @"result":@"emailAlreadyUsed" }];
[self woe:@"That email address is already in use...."];
[PFUser logOut]; .. don't forget that
return;
}
[PFAnalytics trackEvent:@"newAccount"
dimensions:@{ @"result":@"connectionWoe" }];
[self woe:@"Couldn't connect. Please try later"];
return;
}
NSLog(@"step one rego success");
[self _actuallyJoinStepTwo];
... now continue to save other information
... for example user's address, age, avatar photo etc.
}];
}