2017-08-30 67 views
-3

在我的iOS應用程序中有一個登錄頁面來訪問features.I要直接登錄我的註冊指紋。如果有人知道這個功能,請幫助我。如何添加指紋登錄到iOS應用程序

+0

https://developer.apple.com/documentation/ localauthentication/lacontext – Basheer

+1

你到目前爲止嘗試過什麼? –

回答

1

首次進口,

#import <LocalAuthentication/LocalAuthentication.h> 

然後寫.M代碼

- (IBAction)authenicateButtonTapped:(id)sender { 

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

NSError *error = nil; 
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { 
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
      localizedReason:@"Are you the device owner?" 
         reply:^(BOOL success, NSError *error) { 
          dispatch_async(dispatch_get_main_queue(), ^{ 
          if (error) { 
           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                       message:@"There was a problem verifying your identity." 
                      delegate:nil 
                    cancelButtonTitle:@"Ok" 
                    otherButtonTitles:nil]; 
           [alert show]; 
           return; 
          } 

    if (success) { 



           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                       message:@"You are the device owner!" 
                      delegate:nil 
                    cancelButtonTitle:@"Ok" 
                    otherButtonTitles:nil]; 
       [alert show]; 



    } else { 
           UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                       message:@"You are not the device owner." 
                      delegate:nil 
                    cancelButtonTitle:@"Ok" 
                    otherButtonTitles:nil]; 
           [alert show]; 
          } 
          }); 
         }]; 

    } else { 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                message:@"Your device cannot authenticate using TouchID." 
                delegate:nil 
              cancelButtonTitle:@"Ok" 
              otherButtonTitles:nil]; 
    [alert show]; 

} 
} 
+0

我沒有在登錄頁面 –

+0

添加任何身份驗證按鈕,然後請在您的LogInVC ViewDidLoad後調用此代碼後避免第一線即IBAction方法他們做if(成功){//做的東西}行動 –

+0

tq man U挽救了我的生命 –

1

我已經加入GitHub上https://github.com/sumitjain7/AppleTouchId/blob/master/appleTouchId/Classes/AppleAuthenticator.swift

庫目前豆莢,這是行不通的。你可以直接使用這個類。 你只需要做到這一點:

AppleAuthenticator.sharedInstance.authenticateWithSuccess({ 

      let vc = self.storyboard?.instantiateViewController(withIdentifier: "YOUR_VC_IDENTIFIER") 
      //do your stuff here 
     }, failure:{ errorCode in 
      var authErrorString : NSString 
      switch (errorCode) { 
      case LAError.systemCancel.rawValue: 
       authErrorString = "System canceled auth request due to app coming to foreground or background."; 
       break; 
      case LAError.authenticationFailed.rawValue: 
       authErrorString = "User failed after a few attempts."; 
       break; 
      case LAError.userCancel.rawValue: 
       authErrorString = "User cancelled."; 
       break; 

      case LAError.userFallback.rawValue: 
       authErrorString = "Fallback auth method should be implemented here."; 
       break; 
      case LAError.touchIDNotEnrolled.rawValue: 
       authErrorString = "No Touch ID fingers enrolled."; 
       break; 
      case LAError.touchIDNotAvailable.rawValue: 
       authErrorString = "Touch ID not available on your device."; 
       break; 
      case LAError.passcodeNotSet.rawValue: 
       authErrorString = "Need a passcode set to use Touch ID."; 
       break; 
      default: 
       authErrorString = "Check your Touch ID Settings."; 
       break; 
      } 
      // self.presentAlertControllerWithMessage(authErrorString) 
     }) 
相關問題