標籤:通過 代碼 nullable 支付 default ios8 輸入 對象 總結
中指紋識別簡單介紹,在iphone系列中,是從5S以後開始有了指紋識別的功能,在ios8的時候開放的指紋驗證的介面。 所以我們在進行指紋識別應用的時候要去判斷機型以及系統的版本。 代碼如下,下面需要特別注意的其實就是LAPolicyDeviceOwnerAuthentication和LAPolicyDeviceOwnerAuthenticationWithBiometrics的區別,以及檢測系統的版本通過[UIDevice currentDevice].systemVersion.floatValue,判斷裝置是否可用Touch ID就是通過canEvaluatePolicy: error:這個方法來進行判斷。還有需要注意的是下面驗證指紋識別是否成功的操作預設都是在子線程中進行的,所以我們如果要做UI的操作要回到主線程去執行。可用利用dispatch_async(dispatch_queue_t _Nonnull queue, ^{ }) 這個函數來實現,裡面傳入主隊列即可。還有就是我們也可以根據eror的code來進行一些判斷,看使用者具體是因為什麼原因導致的錯誤,然後在作出相應的輸出。
- //1、判斷系統版本是不是大於等於8.0如果大於等於的話就表示可以使用指紋識別
- if([UIDevice currentDevice].systemVersion.floatValue>=8.0)
- {
- //判斷是否可以使用指紋識別的功能,是在5S之後才可以進行使用的
- //建立LA對象的上下文
- LAContext * context = [[LAContext alloc]init];
- //判斷裝置是否支援指紋識別
- //Evaluate 表示評估的意思
- //Policy表示的是策略
- //用來檢查當前裝置是否可用touchID
- if([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil])
- {
- //LAPolicyDeviceOwnerAuthentication如果我們三次指紋輸入的都錯了,就會彈出密碼框,如果不進行密碼輸入。再次進來還可以有兩次機會驗證指紋如果都
- 錯誤還會繼續彈出系統密碼框讓你輸入 如果你沒輸入touch ID就會被鎖定,而LAPolicyDeviceOwnerAuthenticationWithBiometrics不會彈出輸入系統
- 的密碼框,輸入三次錯誤之後,預設不會做任何處理,我們還可以重新再點擊指紋識別進行輸入,但是如果還是輸入錯誤兩次之後touch id就會被鎖定
- //表示可以使用指紋識別技術
- [context evaluatePolicy:LAPolicyDeviceOwnerAuthentication localizedReason:@"請驗證指紋進行支付" reply:^
- (BOOL success, NSError * _Nullable error) {
- //裡面是在子線程中執行的,所以要更新UI的話,肯定是需要回到主線程去執行的
- //判斷是否成功
- if(success)
- {
- NSLog(@"%@",[NSThread currentThread]);
- NSLog(@"驗證成功");
- }
- else
- {
- NSLog(@"驗證失敗");
- }
- NSLog(@"%@",[NSThread currentThread]);
- NSLog(@"%@",error);
- if(error)
- {
- if(error.code==-2)
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIAlertController * vc = [UIAlertController alertControllerWithTitle:@"指紋驗證取消" message:@""
- preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction * action = [UIAlertAction actionWithTitle:@"確認" style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"---------");
- }];
- UIAlertAction * action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
- handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"hhhhhh");
- }];
- [vc addAction:action];
- [vc addAction:action1];
- [self presentViewController:vc animated:YES completion:nil];
- });
- }
- else if(error.code==-1)
- {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIAlertController * vc = [UIAlertController alertControllerWithTitle:@"指紋已經輸錯3次" message:
- @"你還有兩次機會" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction * action = [UIAlertAction actionWithTitle:@"確認" style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"---------");
- }];
- [vc addAction:action];
- [self presentViewController:vc animated:YES completion:nil];
- });
- }
- }
- }];
- }
- }
- else
- {
- NSLog(@"對不起,系統版本過低");
- }
複製代碼總結 以上所述是小編給大家介紹的iOS開發中指紋識別簡單介紹,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對網站的支援! |
http://www.kmjdad.com/
http://www.jnsjzyy.com/
http://www.czhkwl.com/
http://www.express-o2o.com/
http://www.gzjindao.com/
http://www.chumingchuanmeiyishu.com/
http://www.thcxb.com/
http://www.xingguangkeji.com/
http://www.gdrhsy.com/
http://www.clhuiji.com/
http://www.nxjianye.com/
http://www.tjmingsheng.com/
http://www.gangguan022.com/
http://www.zyjbp.com/
http://www.qianhangmy.com/
http://www.tzminbell.com/
iOS開發中指紋識別簡單介紹