Avoid showing UIAlertView when using PFLogInViewController

158 Views Asked by At

I'm using a subclass of the PFLogInViewController in which I want to display errors in a different way to that of the default behaviour which is to pop up a UIAlertView.

Does anyone know if there's a way to avoid showing the UIAlertView? I'm already using the following method, however that doesn't actually allow me to avoid the UIAlertView being shown in the event of a failed login.

- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:(NSString *)username password:(NSString *)password
1

There are 1 best solutions below

0
kishikawa katsumi On BEST ANSWER

PFLogInViewController does not provide hooks to change this behavior. You might want to build your own custom PFLogInViewController subclass and override the method which display alert view when login failed.

Since PFLogInViewController's code has been open sourced, according to it the method which displays an alert view is _loginDidFailWithError.

https://github.com/ParsePlatform/ParseUI-iOS/blob/master/ParseUI/Classes/LogInViewController/PFLogInViewController.m#L382-L390

- (void)_loginDidFailWithError:(NSError *)error {
    if (_delegateExistingMethods.didFailToLogIn) {
        [_delegate logInViewController:self didFailToLogInWithError:error];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:PFLogInFailureNotification object:self];

    NSString *title = NSLocalizedString(@"Login Error", @"Login error alert title in PFLogInViewController");
    [PFUIAlertView showAlertViewWithTitle:title error:error];
}

For example, if you like the following, you can not to display alerts when the login fails. Define MYLogInViewController as subclass of PFLogInViewController

@interface MYLogInViewController : PFLogInViewController

@end

@implementation MYLogInViewController

- (void)_loginDidFailWithError:(NSError *)error {
    if ([self.delegate respondsToSelector:@selector(logInViewController:didFailToLogInWithError:)]) {
        [self.delegate logInViewController:self didFailToLogInWithError:error];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:PFLogInFailureNotification object:self];
}

@end

and use it instead PFLogInViewController

MYLogInViewController *logInViewController = [[MYLogInViewController alloc] init];
logInViewController.delegate = self;
[self presentViewController:logInViewController animated:YES completion:nil];