#import <LocalAuthentication/LocalAuthentication.h>
//指紋識別的操作
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//1. 判斷系統(tǒng)版本
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
//2. LAContext : 本地驗證對象上下文
LAContext *context = [LAContext new];
//3. 判斷是否可用
//Evaluate: 評估 Policy: 策略,方針
//LAPolicyDeviceOwnerAuthenticationWithBiometrics: 允許設(shè)備擁有者使用生物識別技術(shù)
if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"對不起, 指紋識別技術(shù)暫時不可用" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alertView show];
});
}
//4. 開始使用指紋識別
//localizedReason: 指紋識別出現(xiàn)時的提示文字, 一般填寫為什么使用指紋識別
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"開啟了指紋識別, 將打開隱藏功能" reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
NSLog(@"指紋識別成功");
// 指紋識別成功,回主線程更新UI,彈出提示框
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"指紋識別成功" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alertView show];
});
}
if (error) {
// 錯誤的判斷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(@"錯誤: %@",error);
// 指紋識別出現(xiàn)錯誤,回主線程更新UI,彈出提示框
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"指紋驗證失敗" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alertView show];
});
}
}
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"對不起, 該手機不支持指紋識別" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alertView show];
});
}
}
iOS touchID的使用(指紋識別代替密碼)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 在iPhone5s問世后,蘋果的后續(xù)移動設(shè)備相繼添加了指紋功能,從實際使用中還是相當(dāng)方便的,比如快捷支付、快捷登錄...
- 公司的項目因為都涉及用戶信息,因此都使用到了TouchID來身份識別,因此自己也是開始著手看了代碼,了解了這個部分...
- 指紋識別現(xiàn)在很多帶賬戶安全信息的app 都有,下面我對他做了一點點的封裝,用于下次使用更加便捷,也給大家開發(fā)提高點...
- 實用原理: 指紋識別技術(shù)就是把一個人同他的指紋對應(yīng)起來,通過比較他的指紋和預(yù)先保存的指紋進行比較,就可以驗證他的真...