0

我正在尝试检查当前用户是否在继续下一步之前验证了它的电子邮件。我在做什么错请帮助谢谢。在后台保存的电话号码有效..当我调用“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];

}
4

3 回答 3

3
func giveCaketoUser(user: PFUser) {
                if (user.objectForKey("emailVerified").boolValue == true){
                    println("true")
                } else {
                    println("flase")
                }
            }
于 2015-04-18T12:02:44.967 回答
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 错误,但这可能是我的失败而不是方法。

希望这会让你朝着正确的方向前进!

于 2015-01-22T20:33:51.287 回答
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);

}

如果您还没有解决,希望这会有所帮助!

于 2015-02-06T14:38:34.577 回答