iOS9 整合指紋解鎖

來源:互聯網
上載者:User

標籤:

添加依賴庫 LocalAuthentication.framework

#import <LocalAuthentication/LocalAuthentication.h>  // 標頭檔

 

    LAContext *context = [[LAContext alloc] init];

    NSError *error = nil;

  //  這句代碼是讓指紋驗證的提示框沒有輸入密碼

    context.localizedFallbackTitle = @"";

    if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {

        [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"請通過指紋驗證解鎖應用" reply:^(BOOL success, NSError * _Nullable error) {

            if (success) { // 驗證成功

    // 指紋解鎖是在子線程執行的,當你要重新整理UI的時候需要回到主線程,要不然就會看到介面卡死

                dispatch_async(dispatch_get_main_queue(), ^{ 

                    self.dactylogramLbl.text = self.dactylogramSwitch.on ? @"指紋驗證已開啟" : @"指紋驗證未開啟";

                    [kUserDefaults setBool:self.dactylogramSwitch.on forKey:@"isOpenFingerprintPwd"];

               });

            } else {

                if (error.code == kLAErrorUserCancel) { // 點擊了取消

                    NSLog(@"驗證失敗3");               

      } else {

                    NSLog(@"驗證失敗2");

                }

      } else {

        NSLog(@"您的裝置不能使用 TouchID 進行身分識別驗證");

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您的裝置不能使用 TouchID 進行身分識別驗證" delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];

        [alertView show];

    }

iOS9 整合指紋解鎖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.