//
// 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
// 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