指纹识别
蘋果在iOS8之后開啟了指紋識別的功能,如果想讓自己的App能夠使用指紋識別功能,必須要滿足一定的條件才行。開發文檔
1. 必須是iPhone5s之后的設備
2. 系統版本必須在等于或大于iOS8
具體實現
使用指紋識別,必須要引入LocalAuthentication.framework。引入之后,需要
import <LocalAuthentication/LocalAuthentication.h>。實現代碼如下:
//第一步判斷系統版本是否大于或等于iOS8 if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {LAContext *context = [LAContext new];//判斷設備是否支持指紋識別if (![context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {NSLog(@"對不起,指紋識別技術暫時不可用");}//如果支持指紋識別,這是會彈出指紋識別框,進行識別,并根據返回進行相應操作[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"開啟了指紋識別,將打開隱藏功能" reply:^(BOOL success, NSError * _Nullable error) {if (success) {NSLog(@"指紋識別成功");dispatch_async(dispatch_get_main_queue(), ^{UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"指紋識別成功" message:nil delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil];[alertView show];});}if (error) {if (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(@"錯誤: %@",error);// 指紋識別出現錯誤,回主線程更新UI,彈出提示框NSString *code = [NSString stringWithFormat:@"%ld",error.code];UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:code delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];[alertView show];}}}];}else {NSLog(@"對不起,該手機不支持指紋識別");}這里僅說明了啟動指紋識別功能的方法,如果要加入到第三方App中,還需要和相應的服務端配合使用,以完成指紋識別驗證。
錯誤代碼
| LAErrorAuthenticationFailed | 指紋無法識別 |
| LAErrorUserCancel | 用戶點擊了取消 |
| LAErrorUserFallback | 用戶取消,點擊了輸入密碼按鈕 |
| LAErrorSystemCancel | 系統取消,其它應用進入前臺 |
| LAErrorPasscodeNotSet | 驗證無法啟動,因為設備上沒有設置密碼 |
| LAErrorTouchIDNotAvailable | 驗證無法啟動,因為設備上TouchID無效 |
| LAErrorTouchIDNotEnrolled | 驗證無法啟動,因為沒有錄入指紋 |
總結
- 上一篇: 安卓逆向 | 某新闻类APP urlSi
- 下一篇: Cmd Markdown 编辑阅读器