iOS Touch ID指紋識(shí)別技術(shù)簡(jiǎn)介
Touch ID簡(jiǎn)介:
蘋果公司在iPhone 5S手機(jī)中推出了指紋識(shí)別功能,提高手機(jī)安全性的同時(shí)也方便了用戶操作。其功能是通過Touch ID實(shí)現(xiàn)的,從iOS 8系統(tǒng)開始,蘋果開發(fā)一些Touch ID的API使得開發(fā)人員可以在自己的應(yīng)用程序中調(diào)用指紋識(shí)別功能。
Touch ID功能就是指紋識(shí)別密碼。使用指紋識(shí)別功能需要先進(jìn)入設(shè)置—Touch ID 與密碼中根據(jù)提示添加指紋。
從iOS 8系統(tǒng)開始開放了Touch ID的驗(yàn)證接口功能,在應(yīng)用程序中可以判斷輸入的Touch ID是否設(shè)置持有者的Touch ID。
Touch ID使用:
創(chuàng)建一個(gè)iOS工程項(xiàng)目。
打開工程的General — Linked Frameworks and Libraries面板,單機(jī)“+”按鈕添加“LocalAuthentication.framework”框架,如圖26-1所示。
編寫程序時(shí)導(dǎo)入“LocalAuthentication.framework”框架的頭文件:
#import <LocalAuthentication/LocalAuthentication.h>。
寫了一個(gè)簡(jiǎn)單的測(cè)試Touch ID的例子,效果圖如下:(若圖片不清楚可右鍵將圖片保存本地再放大看)

下面貼上代碼:
#import <UIKit/UIKit.h>
@interface HWTouchIDTestVC : UIViewController
@end
#import "HWTouchIDTestVC.h"
#import <LocalAuthentication/LocalAuthentication.h>
@interface HWTouchIDTestVC ()
@property (nonatomic, weak) UILabel *label;
@end
@implementation HWTouchIDTestVC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
//創(chuàng)建控件
[self creatControl];
}
- (void)creatControl
{
//測(cè)試按鈕
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 120, 50)];
btn.backgroundColor = [UIColor orangeColor];
[btn setTitle:@"測(cè)試按鈕" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnOnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
//提示標(biāo)簽
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(220, 200, 120, 50)];
label.text = @"測(cè)試標(biāo)簽";
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor = [UIColor yellowColor];
[self.view addSubview:label];
self.label = label;
}
- (void)btnOnClick
{
//初始化
LAContext *context = [[LAContext alloc] init];
NSError *error = nil;
//顯示的文字
NSString *str = @"指紋驗(yàn)證";
//判斷是否能進(jìn)行驗(yàn)證
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:str reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
NSLog(@"驗(yàn)證成功");
dispatch_async(dispatch_get_main_queue(), ^{
self.label.text = @"驗(yàn)證成功";
self.label.backgroundColor = [UIColor greenColor];
});
}else {
NSLog(@"驗(yàn)證失敗,error:%@", error);
dispatch_async(dispatch_get_main_queue(), ^{
self.label.text = @"驗(yàn)證失敗";
self.label.backgroundColor = [UIColor redColor];
});
}
}];
}else {
NSLog(@"無法驗(yàn)證指紋,error: %@", error);
self.label.text = @"無法驗(yàn)證";
}
}
@end
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
iOS中的應(yīng)用啟動(dòng)原理以及嵌套模型開發(fā)示例詳解
這篇文章主要介紹了iOS中的應(yīng)用啟動(dòng)原理以及嵌套模型開發(fā)示例詳解,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-12-12
iOS Mask屬性的詳細(xì)介紹及應(yīng)用實(shí)例
這篇文章主要介紹了iOS Mask屬性的詳細(xì)介紹的相關(guān)資料,這里對(duì)Mask的屬性進(jìn)行了詳細(xì)說明并附簡(jiǎn)單代碼實(shí)例,幫助大家更直接學(xué)習(xí)理解,這部分知識(shí),需要的朋友可以參考下2016-11-11
iOS中的UITableView的重用機(jī)制與加載優(yōu)化詳解
本篇文章主要介紹了iOS中的UITableView的重用機(jī)制與加載優(yōu)化詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02
IOS計(jì)步器功能實(shí)現(xiàn)之Healthkit和CMPedometer
現(xiàn)在越來越多的人關(guān)注運(yùn)動(dòng)和健康,iOS系統(tǒng)也在很早的時(shí)候就自帶了健康A(chǔ)PP,下面詳細(xì)描述一下在我們開發(fā)中,怎么實(shí)現(xiàn)計(jì)步器功能。2016-08-08
怎么防止ios系統(tǒng)被抓包?防止ios系統(tǒng)被抓包的方法
怎么防止ios系統(tǒng)被抓包?下面小編就為大家分享一篇防止ios系統(tǒng)被抓包的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-12-12
iOS 底部按鈕和應(yīng)用圖標(biāo)顯示未讀消息(帶數(shù)字)
本文主要介紹了iOS 底部按鈕和應(yīng)用圖標(biāo)顯示未讀消息的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-04-04
iOS開發(fā)中對(duì)于攝像頭的一些基本使用方法分享
這篇文章主要介紹了iOS開發(fā)中對(duì)于攝像頭的一些基本使用方法分享,包括判斷攝像頭是否可用的方法,需要的朋友可以參考下2015-10-10

