美文网首页
指纹识别 touch id的简单使用

指纹识别 touch id的简单使用

作者: 华楠 | 来源:发表于2016-12-01 15:59 被阅读0次

主要代码如下

#import <LocalAuthentication/LocalAuthentication.h>//引入头文件


- (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];
}

相关文章

  • 指纹识别 touch id的简单使用

    主要代码如下 上面这段代码是进行验证的关键代码和判断,其中包括验证成功,验证失败,和取消验证。如果验证失败,可以弹...

  • Touch ID

    使用iOS 8 SDK添加Touch ID指纹识别功能 - Puzhi的专栏 - 博客频道 - CS...

  • iOS 指纹识别

    指纹识别: iPhone5S开始,推出指纹识别 iOS8.0之后苹果允许第三方 App 使用 Touch ID进行...

  • iOS Touch ID

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

  • app高大上的指纹识别登陆

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

  • iOS 指纹验证(Touch ID)

    iOS 指纹验证(Touch ID) iOS的指纹识别是一个非常简单的api系统已经封好了,直接调起就行,非常简单...

  • Touch ID使用

    前言:如果图片看不了请移步:简书 Touch ID简介 Touch ID指纹识别作为iPhone 5s上的“杀手级...

  • Touch ID 简单使用

    Touch ID 指纹识别首次应用是在2013年9月发布的iPhone 5s 上。在今天,指纹识别已经是所有智能手...

  • Touch ID

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

  • 五分钟上手 Touch ID

    Touch ID Touch ID是苹果公司的一种指纹识别技术。它作为iPhone 5s上的“杀手级”功能,早已为...

网友评论

      本文标题:指纹识别 touch id的简单使用

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