我试图检查当前用户之前是否已经验证了它的电子邮件 他们继续下一步。我做错了什么,请帮助谢谢。在后台保存的电话号码工作..当我呼叫" SavePhoneInBackground"应用程序崩溃
(SVProgressHUd是活动指标)
-(void) SavePhoneInBackground {
PFUser *user = [PFUser currentUser];
user[@"phone"] = _phone_register.text;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(@"PhoneUpdatingSucces!");
_phone_register.text = nil;
[self checkUserEmailVerify];
}else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"Something went wrong! Try again." delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alert show];
[SVProgressHUD dismiss];
NSLog(@"There was an error in the registration!");
}
}];
}
-(void) checkUserEmailVerify {
PFUser *user = [PFUser currentUser];
if (![[user objectForKey:@"emailVerified"] boolValue]) {
// Refresh to make sure the user did not recently verify
[user refresh];
if (![[user objectForKey:@"emailVerified"] boolValue]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"You need to verify your emailadress!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
return;
[SVProgressHUD dismiss];
}
}
// This is a triumph.
[SVProgressHUD dismiss];
[self performSegueWithIdentifier:@"login2" sender:self];
}
答案 0 :(得分:3)
func giveCaketoUser(user: PFUser) {
if (user.objectForKey("emailVerified").boolValue == true){
println("true")
} else {
println("flase")
}
}
答案 1 :(得分:1)
以下是我最近的一个项目中使用的内容:
- (BOOL)validateEmail:(NSString *)emailStr {
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:emailStr];
}
您可以使用正则表达式的其他操作。当我使用这种方法时,我遇到的问题是项目将继续注册用户,同时仍然显示我的自定义警报和NSLog错误,但这可能是我的失败,而不是方法。
希望这会让你朝着正确的方向前进!
答案 2 :(得分:1)
这是我在我的应用程序中执行此操作的方式,它只会让经过验证的电子邮件用户访问。您需要根据需要稍微修改它。
- (void)logInViewController:(MyLogInViewController *)logInController didLogInUser:(PFUser *)user {
if (![[user objectForKey:@"emailVerified"] boolValue]){
NSLog(@"User not validated email");
[[[UIAlertView alloc] initWithTitle:@"Access restricted" message:@"To access this area please validate your email address" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
}
else if ([[user objectForKey:@"emailVerified"] boolValue]){
NSLog(@"Email validated");
[self dismissViewControllerAnimated:YES completion:NULL];
[[[UIAlertView alloc] initWithTitle:@"Welcome back" message:(@"%@", user.username) delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
}
// [self dismissViewControllerAnimated:YES completion:NULL];
NSLog(@"Login sucessfull and username is %@",user.username);
}
希望如果你还没有解决它,这会有所帮助!