zoukankan      html  css  js  c++  java
  • 指纹识别身份

    最近因为要做一个理财产品,所以指纹识希望加进去,就研究了下,写了段代码

    先在项目中添加QuartzCore.framework和LocalAuthentication.framework

    #import "ViewController.h"

    #import <LocalAuthentication/LocalAuthentication.h>

    @interface ViewController ()

    @property (weak, nonatomic) IBOutlet UIButton *btn;

    @end

    @implementation ViewController

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        _btn.layer.shadowColor = [UIColor grayColor].CGColor;

        _btn.layer.shadowOffset = CGSizeMake(3, 2);

        _btn.layer.shadowOpacity = 0.5;

        _btn.center = self.view.center;

        [_btn setTitle:@"Touch IDTest" forState:UIControlStateNormal];

        [_btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

        

        // Do any additional setup after loading the view, typically from a nib.

    }

    -(void)btnClick:(UIButton *)sender

    {

        [self TouchIDTestSuccess:^

        {

            NSLog(@"       Touch ID     ");

            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示"  message:@"恭喜,您通过了Touch ID身份验证" preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction * cancel= [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:nil];

            [alert addAction:cancel];

            [self presentViewController:alert animated:YES completion:nil];

        } Failure:^(NSError *error)

        {

            

            NSLog(@"        Touch ID     (error)");

            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示"  message:@"抱歉,您未能通过Touch ID身份验证"  preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction * cancel= [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:nil];

            [alert addAction:cancel];

            [self presentViewController:alert animated:YES completion:nil];

            

        } Unvilabe:^(NSError *error)

         {

            NSLog(@"        Touch ID     (error)");

            UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示"  message:@"抱歉,Touch ID不可用"  preferredStyle:UIAlertControllerStyleAlert];

            UIAlertAction * cancel= [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:nil];

            [alert addAction:cancel];

            [self presentViewController:alert animated:YES completion:nil];

        }];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    -(void)TouchIDTestSuccess:(void(^)())successed Failure:(void(^)(NSError * error))failured  Unvilabe:(void(^)(NSError * error))Unvilabe

    {

        LAContext * lauth = [[LAContext alloc]init];

        NSError * error  = nil;

        BOOL isTouchAvalible = [lauth canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics  error:&error];

        if (isTouchAvalible)

        {

            [lauth evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"需要验证您的指纹来确认您的身份信息" reply:^(BOOL success, NSError * _Nullable error)

             {

                 if (success)

                 {

                     if (successed)

                     {

                         successed();

                     }

                 }

                 else

                 {

                     if (failured)

                     {

                         failured(error);

                     }

                 }

             }];

        } else

        {

            if (Unvilabe)

            {

                Unvilabe(error);

            }

        }

    }

  • 相关阅读:
    最大化等比例测试演化Demo-传统方法
    Layout-3相关代码:3列布局代码演化三]
    Layout-3相关代码:3列布局代码演化[二]
    Layout-2相关代码:3列布局代码演化[一]
    Layout-1相关代码
    【比赛打分展示双屏管理系统-专业版】Other.ini 配置文件解读以及排行榜界面及专家评语提交展示等具体配置
    Android 开源简单控件
    Android Drawable资源
    Android Service与Thread的区别
    Android事件处理
  • 原文地址:https://www.cnblogs.com/Hakim/p/5337992.html
Copyright © 2011-2022 走看看