指纹解锁(系统类)__真机

//
//  ViewController.m
//  指纹解锁
//
//  Created by apple on 16/1/22.
//  Copyright © 2016 shuo. All rights reserved.
//

#import "ViewController.h"
#import
<LocalAuthentication/LocalAuthentication.h>

@interface ViewController ()
- (
IBAction )Touch:( UIButton *)sender;

@end

@implementation ViewController

- (
void )viewDidLoad {
    [
super viewDidLoad ];
   
// Do any additional setup after loading the view, typically from a nib.
}

- (
void )didReceiveMemoryWarning {
    [
super didReceiveMemoryWarning ];
   
// Dispose of any resources that can be recreated.
}

// 出错
/*
 
错误信息有三种
 LAErrorTouchIDNotAvailable
设备本身并不具备指纹传感装置。
 LAErrorPasscodeNotSet
设备上并不具备密码设置信息,也就是说 Touch ID 功能处于被禁用状态。
 LAErrorTouchIDNotEnrolled
已经设定有密码机制,但设备配置当中还没有保存过任何指纹内容。
 */



- (
IBAction )Touch:( UIButton *)sender {
//LAContext 这个类代表验证上下文 . 用于评估验证政策
   
LAContext *context =[[ LAContext alloc ] init ];
   
// 就是一个错误对象,一般用在读取文件中,用的超多,或者一些解析,可能会出错的地方都可能遇到
   
NSError *error = nil ;
   
    context.
localizedFallbackTitle = @"enter to password" ;
   
// 判断设备是否支 touchid
   
if ([context canEvaluatePolicy : LAPolicyDeviceOwnerAuthenticationWithBiometrics error :&error]) {
       
// 支持就调用这个方法
        [context
evaluatePolicy : LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason : @" 您可是此设备的主人 " reply :^( BOOL success, NSError * _Nullable error) {
           
if (error) {
               
UIAlertController *alter =[ UIAlertController alertControllerWithTitle : @" 出错 " message : @"id 有问题 " preferredStyle : UIAlertControllerStyleAlert ];
               
UIAlertAction *okAction =[ UIAlertAction actionWithTitle : @" 确定 " style : UIAlertActionStyleDefault handler : nil ];
                [alter
addAction :okAction];
                [
self presentViewController :alter animated : YES completion : nil ];
               
               
               
// 验证通过
            }
if (success){
               
               
UIAlertController *a =[ UIAlertController alertControllerWithTitle : @"ok" message : @" 这爪子是我主人的 " preferredStyle : UIAlertControllerStyleAlert ];
               
                
UIAlertAction *ok =[ UIAlertAction actionWithTitle : @" 确定 " style : UIAlertActionStyleDefault handler : nil ];
                [a
addAction :ok];
                [
self presentViewController :a animated : YES completion : nil ];
               
// 验证不通过
            }
else {
               
               
UIAlertController *a =[ UIAlertController alertControllerWithTitle : @"no" message : @" 这爪子不是我主人的 " preferredStyle : UIAlertControllerStyleAlert ];
               
               
UIAlertAction *ok =[ UIAlertAction actionWithTitle : @" 确定 " style : UIAlertActionStyleDefault handler : nil ];
                [a
addAction :ok];
                [
self presentViewController :a animated : YES completion : nil ];
               
            }
           
        }];
       
// 设备不支持 TouchId
    }
else {
       
       
UIAlertController *a =[ UIAlertController alertControllerWithTitle : @" 提示 " message : @" 设备不支持 touchId" preferredStyle : UIAlertControllerStyleAlert ];
       
       
UIAlertAction *ok =[ UIAlertAction actionWithTitle : @" 确定 " style : UIAlertActionStyleDefault handler : nil ];
        [a
addAction :ok];
        [
self presentViewController :a animated : YES completion : nil ];
       
    }
}
@end































































































  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值