避免在使用PFLogInViewController时显示UIAlertView



我正在使用PFLogInViewController的子类,我想在其中以与弹出UIAlertView的默认行为不同的方式显示错误。

有谁知道是否有办法避免显示UIAlertView?我已经在使用以下方法,但是这实际上不允许我避免在登录失败时显示UIAlertView

- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:(NSString *)username password:(NSString *)password
PFLogInViewController不提供

钩子来更改此行为。您可能希望构建自己的自定义PFLogInViewController子类,并重写在登录失败时显示警报视图的方法。

由于PFLogInViewController的代码是开源的,因此根据它,显示警报视图的方法_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];
}

例如,如果您喜欢以下内容,则在登录失败时不能显示警报。将MYLogInViewController定义为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

并改用它PFLogInViewController

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

最新更新