Use of Touch ID (Fingerprint Identification Technology) in iOS

Apple opened up fingerprint recognition technology after iOS8, and encapsulated it into the LocalAuthentication framework, which means that third-party apps are allowed to authenticate through touch ID, and the method of use is extremely simple.

touch ID usage process

1 Import the LocalAuthentication/LocalAuthentication.h framework
2 Make various conditional judgments, and start using if the conditions are met

    // 判断设备是否支持touchId
    if ([[UIDevice currentDevice].systemVersion floatValue] < 8.0) {
        NSLog(@"系统版本太低,无法进行指纹识别");
        return;
    }

    // 创建验证对象的上下文
    LAContext *context = [[LAContext alloc]init];

    // 判断设备是否允许使用生物识别技术
    if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
         NSLog(@"指纹识别技术暂不可用");
        return;
    }

    // 如果条件都满足则开始使用指纹识别
    // localizedReason 传入使用指纹识别的原因
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"验证指纹,以便打开程序" reply:^(BOOL success, NSError * _Nullable error) {

        // 指纹识别成功
        if (success) {
            NSLog(@"指纹识别成功");
        }

        // 指纹识别失败
        switch (error.code){
            case LAErrorSystemCancel:
                // 可能是您将程序切换出去了,所以系统取消了验证
                NSLog(@"系统取消了验证");
                break;
            case LAErrorUserCancel:
                NSLog(@"用户取消了验证");
                break;
            case LAErrorUserFallback:
                // 用户选择输入密码,切换到主线程进行后续处理
                NSLog(@"用户选择输入密码");
                break;
        }
    }];

The following figure is an example of the pop-up fingerprint recognition pop-up window
write picture description here
. The first touchID is the name of the app, and the "verify fingerprint to open the program" below is the incoming use reason.
write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325993618&siteId=291194637