指紋識別是在iOS8.0以後才推出的,所以我們如果想把指紋集成到我們的APP當中,我們首先就要在代碼中判斷iOS版本。
先提示指紋識別,如果不支持或者主動取消,則需要手動輸入密碼認證
第一步需要判定系統版本,如果不支持,我們直接返回,即可
1 if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
2 [self inputUserInfo];
3 return;
4 }
第二步,判斷手機是否支持指紋識別,我們要使用到一個LAContext類
1 //創建LAContext
2 LAContext *ctx = [[LAContext alloc] init];
3 // 判斷設備是否支持指紋識別
4 if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]) {
5
6 //識別代碼部分
7 }
第三步,在第二步的“識別代碼部分”填寫正經的識別代碼
1 //創建LAContext
2 LAContext *ctx = [[LAContext alloc] init];
3 // 判斷設備是否支持指紋識別
4 if ([ctx canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:NULL]) {
5
6 NSLog(@"請按手指");
7
8 // 輸入指紋 - 回調是異步的
9 [ctx evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"提示文字" reply:^(BOOL success, NSError *error) {
10
11
12 // 1. 如果輸入成功
13 if (success) {
14 //成功
15 } else {
16 // 判斷錯誤類型是否是主動自行輸入密碼
17 if (error.code == LAErrorUserFallback) {
18 dispatch_async(dispatch_get_main_queue(), ^{
19 //密碼驗證方法
20 });
21 }
22 }
23 }];
24 } else {
25
26 //密碼驗證方法
27 }
本文有因爲問題請聯繫
QQ:563699115
Telephone:18341266547