지문 인식 터치 id의 간단한 사용

2884 단어
주요 코드는 다음과 같다.
#import //     


- (void)yanzheng
{
    LAContext *lac = [[LAContext alloc] init];
    BOOL isSupport = [lac canEvaluatePolicy:kLAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL];
    lac.localizedFallbackTitle = NSLocalizedString(@"     ", nil);
    if (isSupport) {
        [lac evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"     Touch ID" reply:^(BOOL success, NSError * _Nullable error) {
            if (success) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"  " message:@"    " delegate:self cancelButtonTitle:@" " otherButtonTitles:nil, nil];
                    [alert show];
                });
            }else if([error.userInfo[@"NSLocalizedDescription"] isEqualToString:@"Canceled by user."]){
                dispatch_async(dispatch_get_main_queue(), ^{
                    return ;
                });
            }else{
                dispatch_async(dispatch_get_main_queue(), ^{
                   [self alertViewWithEnterPassword:YES];
                });
            }
        }];
    }else{
        NSLog(@"       ");
    }
}

위의 코드는 검증을 진행하는 관건적인 코드와 판단으로 검증 성공, 검증 실패, 검증 취소를 포함한다.유효성 검사에 실패하면 다음과 같은 암호를 입력하는 프롬프트 상자를 팝업할 수 있습니다.
- (void)alertViewWithEnterPassword:(BOOL)isTrue
{
    UIAlertController *alert;
    if (isTrue) {
        alert = [UIAlertController alertControllerWithTitle:@"     " message:@"         " preferredStyle:UIAlertControllerStyleAlert];
    }else{
        alert = [UIAlertController alertControllerWithTitle:@"    " message:@"         " preferredStyle:UIAlertControllerStyleAlert];
    }
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.secureTextEntry = YES;
    }];
    UIAlertAction *backAction = [UIAlertAction actionWithTitle:@"      " style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [self yanzheng];
    }];
    
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if ([alert.textFields.firstObject.text isEqualToString:@"123"]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"  " message:@"    " delegate:self cancelButtonTitle:@" " otherButtonTitles:nil, nil];
            [alert show];
        }else{
            [self alertViewWithEnterPassword:NO];
        }
    }];
    [alert addAction:backAction];
    [alert addAction:confirmAction];
    [self presentViewController:alert animated:YES completion:nil];
}

좋은 웹페이지 즐겨찾기