I don't want the function to return false if the user enters invalid login credentials. I made a __block BOOL but that hasn't worked. I took a look at this post Return value for function inside a block and I don't understand how to implement a callback. How would that work in this scenario?
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
__block BOOL ret=YES;
NSString *phoneNumberField = [self.phoneNumberField.text stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *passwordField = [self.passwordField.text stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
PFUser *newUser = [PFUser user];
newUser.username = phoneNumberField;
newUser.password = passwordField;
if ([identifier isEqualToString:@"Verify"]) {
if([newUser.username length] == 0 || [newUser.password length] == 0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops! Sorry"
message:@"Please make sure you enter both a phone number and a password!" delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
return NO;
}
else
{
//PROBLEM IS BELOW
[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if(!error)
{
ret = YES;
NSLog(@"Successful login");
}
else
{
ret = NO;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:@"That phone number is already in use" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
}
}];
}
return ret;
} else {
return YES;
}
}