每次弹出LAContext

时间:2016-06-17 07:31:44

标签: ios objective-c swift ios8 ios9

- (void)touchIdIntegration{
    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;    
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {

    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
              localizedReason:@"Authenticate via Touch ID to unlock the app"
                        reply:^(BOOL success, NSError *error) {

                            if (success) {
                                dispatch_async(dispatch_get_main_queue(), ^{

                                    [[AppManager instance].helpManager setDontShowInterstialAd:TRUE];
                                    [[AppManager instance].cycleManager setUserAuthenticated:TRUE];
                                    [self.delegate showAlertViewsOnServerData];

                                });
                            } else {
                                dispatch_async(dispatch_get_main_queue(), ^{


                                    switch (error.code) {
                                        case kLAErrorAuthenticationFailed:
                                            NSLog(@"kLAErrorAuthenticationFailed");
                                            break;
                                        case kLAErrorTouchIDNotEnrolled:
                                            NSLog(@"kLAErrorTouchIDNotEnrolled");
                                            break;
                                        case LAErrorPasscodeNotSet:
                                            NSLog(@"LAError code ");
                                            break;
                                        default:
                                            break;
                                    }
                                });
                            }
                        }];
    } else {
    dispatch_async(dispatch_get_main_queue(), ^{
        self.m_imgFingerPrint.hidden = YES;
        NSLog(@"LAError code %ld",authError.code);
        NSString *alertMessage =nil;

        switch (authError.code) {
            case kLAErrorAuthenticationFailed:
            {
                alertMessage = @"kLAErrorAuthenticationFailed" ;

        }
                break;
            case kLAErrorTouchIDNotEnrolled:
                alertMessage = @"kLAErrorTouchIDNotEnrolled" ;
                break;
            case LAErrorPasscodeNotSet:
                alertMessage = @"LAErrorPasscodeNotSet" ;
                break;
            default:
                break;
        }
 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                    message:alertMessage
                                                                   delegate:self
                                                          cancelButtonTitle:@"OK"
                                                          otherButtonTitles:nil, nil];
                [alertView show];

    });
}
}

我不希望每次用户移动到此屏幕时都会弹出。是否可能?请告诉我。

请找到以下屏幕截图: enter image description here

无论如何都要提前感谢。

1 个答案:

答案 0 :(得分:0)

请勿撰写此代码viewDidLoadviewDidAppear。只有在绝对需要提出touchID时才写它。

相关问题