iOS Touch ID使用,iostouchid使用

來源:互聯網
上載者:User

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部落格園看到本文,請點擊查看原文.

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.