iOS指纹识别技术
實(shí)用原理:
指紋識(shí)別技術(shù)就是把一個(gè)人同他的指紋對(duì)應(yīng)起來,通過比較他的指紋和預(yù)先保存的指紋進(jìn)行比較,就可以驗(yàn)證他的真實(shí)身份。
指紋識(shí)別概念闡述:http://baike.so.com/doc/6246764-6460171.html
在iOS中的發(fā)展過程:
蘋果從iPhone5S開始,具有指紋識(shí)別技術(shù)。但是,是從iOS8.0之后程序員具有使用指紋識(shí)別的權(quán)利——蘋果允許第三方 App 使用 Touch ID 實(shí)現(xiàn)免密碼登陸。
蘋果在iPhone 5s上采用的指紋識(shí)別技術(shù)來自AuthenTec。2012年6月,蘋果收購了這家公司。在被蘋果收購之前,AuthenTec是全球最大的指紋識(shí)別芯片供應(yīng)商,擁有名為TurePrint的專利技術(shù),可以讀取皮膚表皮之下的真皮層信息。
實(shí)際應(yīng)用:
目前QQ、微信、支付寶等主流APP大都已支持指紋登錄或指紋支付。
使用時(shí)涉及關(guān)鍵點(diǎn):
代碼技術(shù)流程:
首先導(dǎo)入框架#import <LocalAuthentication/LocalAuthentication.h>
如果可用,開始調(diào)用方法開始使用指紋識(shí)別
注意:
1、代碼中最好做錯(cuò)誤處理
2、如果指紋識(shí)別成功后,有操作需要更新UI,那么一定在主線程中。
具體看代碼吧!
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ //1. 判斷系統(tǒng)版本 if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
//2. LAContext : 本地驗(yàn)證對(duì)象上下文LAContext *context = [LAContext new];//3. 判斷是否可用//Evaluate: 評(píng)估 Policy: 策略,方針//LAPolicyDeviceOwnerAuthenticationWithBiometrics: 允許設(shè)備擁有者使用生物識(shí)別技術(shù)if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {NSLog(@"對(duì)不起, 指紋識(shí)別技術(shù)暫時(shí)不可用");}//4. 開始使用指紋識(shí)別//localizedReason: 指紋識(shí)別出現(xiàn)時(shí)的提示文字, 一般填寫為什么使用指紋識(shí)別[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"開啟了指紋識(shí)別, 將打開隱藏功能" reply:^(BOOL success, NSError * _Nullable error) {if (success) {NSLog(@"指紋識(shí)別成功"); // 指紋識(shí)別成功,回主線程更新UI,彈出提示框dispatch_async(dispatch_get_main_queue(), ^{UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"指紋識(shí)別成功" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];[alertView show];});}if (error) {// 錯(cuò)誤的判斷chuliif (error.code == -2) {NSLog(@"用戶取消了操作");// 取消操作,回主線程更新UI,彈出提示框dispatch_async(dispatch_get_main_queue(), ^{UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"用戶取消了操作" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];[alertView show];});} else {NSLog(@"錯(cuò)誤: %@",error);// 指紋識(shí)別出現(xiàn)錯(cuò)誤,回主線程更新UI,彈出提示框UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:error delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];[alertView show];}}}];} else {
NSLog(@"對(duì)不起, 該手機(jī)不支持指紋識(shí)別");}
}`
總結(jié)
- 上一篇: 实现socket监听所有网络命名空间
- 下一篇: 2020年IT运维市场大前景到底怎么样