国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS Touch ID指紋識別技術簡介

2020-07-26 02:20:08
字體:
來源:轉載
供稿:網友

Touch ID簡介:

蘋果公司在iPhone 5S手機中推出了指紋識別功能,提高手機安全性的同時也方便了用戶操作。其功能是通過Touch ID實現的,從iOS 8系統開始,蘋果開發一些Touch ID的API使得開發人員可以在自己的應用程序中調用指紋識別功能。

Touch ID功能就是指紋識別密碼。使用指紋識別功能需要先進入設置―Touch ID 與密碼中根據提示添加指紋。

從iOS 8系統開始開放了Touch ID的驗證接口功能,在應用程序中可以判斷輸入的Touch ID是否設置持有者的Touch ID。

Touch ID使用:

創建一個iOS工程項目。           

打開工程的General ― Linked Frameworks and Libraries面板,單機“+”按鈕添加“LocalAuthentication.framework”框架,如圖26-1所示。

編寫程序時導入“LocalAuthentication.framework”框架的頭文件:

#import <LocalAuthentication/LocalAuthentication.h>。

寫了一個簡單的測試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];  //創建控件 [self creatControl];} - (void)creatControl{ //測試按鈕 UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(50, 200, 120, 50)]; btn.backgroundColor = [UIColor orangeColor]; [btn setTitle:@"測試按鈕" forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnOnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn];  //提示標簽 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(220, 200, 120, 50)]; label.text = @"測試標簽"; 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 = @"指紋驗證"; //判斷是否能進行驗證 if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:str reply:^(BOOL success, NSError * _Nullable error) {  if (success) { NSLog(@"驗證成功"); dispatch_async(dispatch_get_main_queue(), ^{  self.label.text = @"驗證成功";  self.label.backgroundColor = [UIColor greenColor]; });  }else { NSLog(@"驗證失敗,error:%@", error); dispatch_async(dispatch_get_main_queue(), ^{  self.label.text = @"驗證失敗";  self.label.backgroundColor = [UIColor redColor]; }); } }];  }else { NSLog(@"無法驗證指紋,error: %@", error); self.label.text = @"無法驗證"; }} @end

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 原平市| 施秉县| 拜城县| 太湖县| 拉萨市| 浦江县| 什邡市| 上栗县| 卢湾区| 松原市| 贵港市| 察隅县| 兴国县| 玛纳斯县| 上虞市| 顺昌县| 朔州市| 双峰县| 兴安县| 西峡县| 香港| 武安市| 云龙县| 扎囊县| 马公市| 定州市| 和林格尔县| 镇安县| 新野县| 博客| 福海县| 永和县| 综艺| 安福县| 和硕县| 林州市| 商河县| 綦江县| 军事| 长春市| 周口市|