#import <LocalAuthentication/LocalAuthentication.h>
//指紋識(shí)別的操作
-(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]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"對(duì)不起, 指紋識(shí)別技術(shù)暫時(shí)不可用" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alertView show];
});
}
//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ò)誤的判斷chuli
if (error.code == -2) {
// 取消操作,回主線程更新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,彈出提示框
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"指紋驗(yàn)證失敗" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alertView show];
});
}
}
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"對(duì)不起, 該手機(jī)不支持指紋識(shí)別" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alertView show];
});
}
}
iOS touchID的使用(指紋識(shí)別代替密碼)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
推薦閱讀更多精彩內(nèi)容
- 在iPhone5s問世后,蘋果的后續(xù)移動(dòng)設(shè)備相繼添加了指紋功能,從實(shí)際使用中還是相當(dāng)方便的,比如快捷支付、快捷登錄...
- 公司的項(xiàng)目因?yàn)槎忌婕坝脩粜畔ⅲ虼硕际褂玫搅薚ouchID來身份識(shí)別,因此自己也是開始著手看了代碼,了解了這個(gè)部分...
- 指紋識(shí)別現(xiàn)在很多帶賬戶安全信息的app 都有,下面我對(duì)他做了一點(diǎn)點(diǎn)的封裝,用于下次使用更加便捷,也給大家開發(fā)提高點(diǎn)...
- 實(shí)用原理: 指紋識(shí)別技術(shù)就是把一個(gè)人同他的指紋對(duì)應(yīng)起來,通過比較他的指紋和預(yù)先保存的指紋進(jìn)行比較,就可以驗(yàn)證他的真...