欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS 指紋解鎖驗(yàn)證TouchID功能

 更新時(shí)間:2017年03月08日 15:42:46   作者:鴻鵠當(dāng)高遠(yuǎn)  
這篇文章主要介紹了iOS 指紋解鎖驗(yàn)證TouchID功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

1、首先,引入依賴框架 LocalAuthentication.framework

#import <LocalAuthentication/LocalAuthentication.h>

2、然后,判斷系統(tǒng)是否為iOS8及以上

//iOS8.0后才支持指紋識(shí)別接口
  if ([UIDevice currentDevice].systemVersion.floatValue < 8.0) {
    return;
  }

3、最后,在APP啟動(dòng)時(shí)調(diào)用以下方法即可完成指紋解鎖的全部功能集成

- (void)evaluateAuthenticate
{
  //創(chuàng)建LAContext
  LAContext* context = [[LAContext alloc] init];
  NSError* error = nil;
  NSString* result = @"請(qǐng)驗(yàn)證已有指紋";
  //首先使用canEvaluatePolicy 判斷設(shè)備支持狀態(tài)
  if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
    //支持指紋驗(yàn)證
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:result reply:^(BOOL success, NSError *error) {
      if (success) {
        //驗(yàn)證成功,主線程處理UI
      }
      else
      {
        NSLog(@"%@",error.localizedDescription);
        switch (error.code) {
          case LAErrorSystemCancel:
          {
            //系統(tǒng)取消授權(quán),如其他APP切入
            break;
          }
          case LAErrorUserCancel:
          {
            //用戶取消驗(yàn)證Touch ID
            break;
          }
          case LAErrorAuthenticationFailed:
          {
            //授權(quán)失敗
            break;
          }
          case LAErrorPasscodeNotSet:
          {
            //系統(tǒng)未設(shè)置密碼
            break;
          }
          case LAErrorTouchIDNotAvailable:
          {
            //設(shè)備Touch ID不可用,例如未打開
            break;
          }
          case LAErrorTouchIDNotEnrolled:
          {
            //設(shè)備Touch ID不可用,用戶未錄入
            break;
          }
          case LAErrorUserFallback:
          {
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
              //用戶選擇輸入密碼,切換主線程處理
            }];
            break;
          }
          default:
          {
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
              //其他情況,切換主線程處理
            }];
            break;
          }
        }
      }
    }];
  }
  else
  {
    //不支持指紋識(shí)別,LOG出錯(cuò)誤詳情
    NSLog(@"不支持指紋識(shí)別");
    switch (error.code) {
      case LAErrorTouchIDNotEnrolled:
      {
        NSLog(@"TouchID is not enrolled");
        break;
      }
      case LAErrorPasscodeNotSet:
      {
        NSLog(@"A passcode has not been set");
        break;
      }
      default:
      {
        NSLog(@"TouchID not available");
        break;
      }
    }
    NSLog(@"%@",error.localizedDescription);
  }
}

以上所述是小編給大家介紹的iOS 指紋解鎖驗(yàn)證TouchID功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論