iOS Touch ID

作者: 72行代码 | 来源:发表于2019-02-20 17:35 被阅读0次
// 导入头文件
#import <LocalAuthentication/LocalAuthentication.h>

- (void)userFigerprintAuthenticationTipsStr:(NSString *)tipsStr{
    //初始化上下文对象
    LAContext *context = [[LAContext alloc] init];
    // 验证失败后系统弹出框右边的按钮title默认为输入密码
    context.localizedFallbackTitle = @"默认为输入密码";
    NSError *err = nil;
    
    // 判断设备是否支持指纹解锁
    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&err]) {
        //支持指纹验证
        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:tipsStr reply:^(BOOL success, NSError * _Nullable error) {
            if (success) {
                NSLog(@"验证成功");
            }else{
                /**********************************************************************
                 /// Authentication was not successful, because user failed to provide valid credentials.
                 LAErrorAuthenticationFailed = kLAErrorAuthenticationFailed,
                 
                 /// Authentication was canceled by user (e.g. tapped Cancel button).
                 LAErrorUserCancel           = kLAErrorUserCancel,
                 
                 /// Authentication was canceled, because the user tapped the fallback button (Enter Password).
                 LAErrorUserFallback         = kLAErrorUserFallback,
                 
                 /// Authentication was canceled by system (e.g. another application went to foreground).
                 LAErrorSystemCancel         = kLAErrorSystemCancel,
                 
                 /// Authentication could not start, because passcode is not set on the device.
                 LAErrorPasscodeNotSet       = kLAErrorPasscodeNotSet,
                 
                 /// Authentication could not start, because Touch ID is not available on the device.
                 LAErrorTouchIDNotAvailable  = kLAErrorTouchIDNotAvailable,
                 
                 /// Authentication could not start, because Touch ID has no enrolled fingers.
                 LAErrorTouchIDNotEnrolled   = kLAErrorTouchIDNotEnrolled,
                 
                 /// Authentication was not successful, because there were too many failed Touch ID attempts and
                 /// Touch ID is now locked. Passcode is required to unlock Touch ID, e.g. evaluating
                 /// LAPolicyDeviceOwnerAuthenticationWithBiometrics will ask for passcode as a prerequisite.
                 LAErrorTouchIDLockout   NS_ENUM_AVAILABLE(10_11, 9_0) = kLAErrorTouchIDLockout,
                 
                 /// Authentication was canceled by application (e.g. invalidate was called while
                 /// authentication was in progress).
                 LAErrorAppCancel        NS_ENUM_AVAILABLE(10_11, 9_0) = kLAErrorAppCancel,
                 
                 /// LAContext passed to this call has been previously invalidated.
                 LAErrorInvalidContext   NS_ENUM_AVAILABLE(10_11, 9_0) = kLAErrorInvalidContext
                 
                 *********************************************************************/
                // 验证失败的几种情况
                switch (error.code) {
                        // 授权失败
                    case LAErrorAuthenticationFailed:
                        NSLog(@"LAErrorSystemCancel");
                        break;
                        
                        // 用户取消
                    case LAErrorUserCancel:
                        NSLog(@"LAErrorUserCancel");
                        break;
                        
                        // 验证失败
                    case LAErrorUserFallback:
                        NSLog(@"LAErrorUserFallback");
                        break;
                        
                        // 切换到其他APP,系统取消验证Touch ID
                    case LAErrorSystemCancel:
                        NSLog(@"LAErrorAppCancel");
                        break;
                        
                        // 系统未设置密码
                    case LAErrorPasscodeNotSet:
                        NSLog(@"LAErrorSystemCancel");
                        break;
                        
                        // 设备Touch ID不可用,例如未打开
                    case LAErrorTouchIDNotAvailable:
                        NSLog(@"LAErrorTouchIDNotAvailable");
                        break;
                        
                        // 设备Touch ID不可用,用户未录入
                    case LAErrorTouchIDNotEnrolled:
                        NSLog(@"LAErrorTouchIDNotEnrolled");
                        break;
                        
                    case LAErrorTouchIDLockout:
                        NSLog(@"LAErrorTouchIDLockout");
                        break;
                        
                    case LAErrorAppCancel:
                        NSLog(@"LAErrorAppCancel");
                        break;
                        
                    case LAErrorInvalidContext:
                        NSLog(@"LAErrorAppCancel");
                        break;
                        
                    default:
                        break;
                }
            }
        }];
    }else{
        NSLog(@"不支持touch id");
    }
}

附:我的博客地址

相关文章

  • iOS Touch ID

    附:我的博客地址

  • iOS Touch ID

    iOS Touch ID 支持系统和机型 iOS系统的指纹识别功能最低支持的机型为iPhone 5s,最低支持系统...

  • iOS Touch ID

    iOS 8 SDK向开发者公开了Touch ID指纹识别功能,允许App对用户身份进行本地验证。使用Touch I...

  • iOS Touch ID

    iOS指纹解锁这个需求在一些软件上可能会有需要,比如支付宝的指纹解锁之类的。前几天有个?友问这个,正好看了一下。很...

  • 初级_iOS Touch ID

    iPhone5以上设备不支持Touch ID,iPhone5s并且iOS 8 SDK开始支持Touch ID。 配...

  • Swift/iOS - Touch ID

    指纹技术是苹果2013年在iPhone5s(iOS7)上开始应用的。iOS7是不允许开发人员来使用TouchAPI...

  • iOS Touch ID 开发

    Touch ID Touch ID是iPhone5S后加入的一项新的功能,也就是大家熟知的指纹识别技术。大家用得最...

  • iOS Touch ID及Face ID

    最近项目中需要使用Touch ID以及Face ID来进行登录验证,以前没遇到过,所以在此写篇文章记录了一下。 T...

  • 【iOS】Touch ID 和Face ID

    Touch ID 和Face ID识别

  • iOS TouchID 认证(仅限设备支持指纹识别)

    iOS 8的SDK开放了Touch ID的接口.从WWDC的视频中可以看到Touch ID应用在两个方面:用于Ke...

网友评论

    本文标题:iOS Touch ID

    本文链接:https://www.haomeiwen.com/subject/bvdiyftx.html