添加指纹识别功能
iPhone 5S開始硬件支持指紋識別功能,在iOS 8以后支持指紋識別,今天隨意試了試指紋識別功能的識別,寫了一個小demo
1.環境
引入頭文件
#import <LocalAuthentication/LocalAuthentication.h>
2.創建兩個頁面
第一個頁面添加一個button,用來觸發指紋識別的功能
第二個頁面就加個label//
// ViewController.m // FingerPrint // // Created by Silence on 16/1/22. // Copyright (c) 2016年 Silence. All rights reserved. //#import "ViewController.h" #import "SecondViewController.h" #import <LocalAuthentication/LocalAuthentication.h>@interface ViewController () {LAContext * _context; } @end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib. }- (IBAction)buttonDidClick:(id)sender {_context = [[LAContext alloc]init];BOOL isSupport = [_context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil];if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"當前系統版本不支持指紋識別" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction * action = [UIAlertAction actionWithTitle:@"提示" style:UIAlertActionStyleDefault handler:nil];[alert addAction:action];[self presentViewController:alert animated:YES completion:nil];}else if (!isSupport){UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"當前設備不支持指紋識別" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction * action = [UIAlertAction actionWithTitle:@"提示" style:UIAlertActionStyleDefault handler:nil];[alert addAction:action];[self presentViewController:alert animated:YES completion:nil];}else{[_context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"請按手印" reply:^(BOOL success, NSError *error) {if(success){//這部分處理驗證成功的邏輯SecondViewController * se = [[SecondViewController alloc]init];[self presentViewController:se animated:YES completion:nil];
}}];}}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }@end
指紋識別功能的初步集成還是比較簡單的。
?
轉載于:https://www.cnblogs.com/easyfly/p/5151699.html
總結
- 上一篇: 3-5:HTTP协议之Cookie和Se
- 下一篇: SMACH专题(一)----安装与初探