iOS Touch ID使用,iostouchid使用
1.首先匯入標頭檔
#import <LocalAuthentication/LocalAuthentication.h>
2.關鍵代碼
- (void)validateTouchID { LAContext *context = [[LAContext alloc] init]; NSError *error; NSString *tip = @"通過Home鍵驗證已有手機指紋"; // 判斷手機是否有指紋 if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:tip reply:^(BOOL success, NSError *error) { if (success) { // 驗證成功 NSLog(@"success"); } else { NSLog(@"%@",error.description); switch (error.code) { case LAErrorSystemCancel: NSLog(@"系統取消授權"); break; case LAErrorUserCancel: NSLog(@"使用者取消"); break; case LAErrorUserFallback: NSLog(@"使用者輸入密碼"); break; default: break; } } }]; } else { NSLog(@"不支援指紋識別,%@",error.description); }}
3.LAError枚舉相關解釋
typedef NS_ENUM(NSInteger, LAError) { /// 認證不成功,因為使用者沒有提供有效憑據 LAErrorAuthenticationFailed = kLAErrorAuthenticationFailed, /// 被使用者取消驗證(例如:“取消”按鈕)。 LAErrorUserCancel = kLAErrorUserCancel, /// 認證被取消了,因為使用者點擊回退按鈕(輸入密碼)。 LAErrorUserFallback = kLAErrorUserFallback, /// 通過系統(例如另一個應用程式的應用程式)被取消驗證。 LAErrorSystemCancel = kLAErrorSystemCancel, /// 認證無法啟動,因為密碼沒有設定在裝置。 LAErrorPasscodeNotSet = kLAErrorPasscodeNotSet, /// 無法啟動驗證,因為在裝置上不提供觸摸標識。 LAErrorTouchIDNotAvailable = kLAErrorTouchIDNotAvailable, /// 無法啟動驗證,因為觸摸標識沒有註冊手指。 LAErrorTouchIDNotEnrolled = kLAErrorTouchIDNotEnrolled,} NS_ENUM_AVAILABLE(10_10, 8_0);
4.
如果你不是在wb145230部落格園看到本文,請點擊查看原文.