2014-10-16 3 views
7

지침과 애플의 Touch ID API 예제를 따라했습니다. 내 응용 프로그램에서 예제를 사용했습니다. Touch ID를 사용하여 로그인 할 수있었습니다. 그러나 문제는 반응이 매우 느리다는 것입니다. 터치 ID에 손가락을 대고 10 초 이상 기다렸다가 성공/실패 여부를 확인해야합니다. app 위임 파일에서 코드를 사용했습니다. 나는 또한 다른 애플 리케이션으로 테스트했지만 결과는 동일한 "지연된 응답"입니다. 얘들 아 나 ​​좀 도와 줘.터치 ID API가 반응이 매우 느림

+0

코드를 디스패치 큐에 써야합니까? – user4150758

+0

나는 이것을 또한 알아 차렸다. 나는 애플의 예를 따랐다. 콜백을 받기까지는 상당한 시간이 걸렸다. 누군가에 대한 답변이 있기를 바란다. 애플의 설명서가 부족하기 때문이다. – Inertiatic

+0

예. 하지만 1password가 어떻게 완벽하게 작동하는지 확신 할 수 없습니다. – user4150758

답변

22
LAContext *myContext = [[LAContext alloc] init]; 

NSError *authError = nil; 

NSString *myLocalizedReasonString = <#String explaining why app needs authentication#>; 

if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) { 

    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
       localizedReason:myLocalizedReasonString 
         reply:^(BOOL success, NSError *error) { 

          if (success) { 
            // User authenticated successfully, take appropriate action 
            dispatch_async(dispatch_get_main_queue(), ^{ 
              // write all your code here 
           }); 
          } else { 
            // User did not authenticate successfully, look at error and take appropriate action 

           switch (error.code) { 
            case LAErrorAuthenticationFailed: 
             NSLog(@"Authentication Failed"); 
             break; 

            case LAErrorUserCancel: 
             NSLog(@"User pressed Cancel button"); 
             break; 

            case LAErrorUserFallback: 
             NSLog(@"User pressed \"Enter Password\""); 
             break; 

            default: 
             NSLog(@"Touch ID is not configured"); 
             break; 
           } 

           NSLog(@"Authentication Fails"); 
          } 
         }]; 
} else { 
    // Could not evaluate policy; look at authError and present an appropriate message to user 
} 
+0

@vishal ... 고맙습니다. 그것은 완벽하게 작동했습니다 :) – user4150758

+0

@ user4150758 welcome .. !! –

+0

누군가 블록 실행 후 스레드가 수행하는 작업을 설명 할 수 있습니까? – Rainelz

6

당신은 다른}

dispatch_async(dispatch_get_main_queue(), ^{ 
//update ui 
}); 

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

NSError *error = nil; 

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

NSError *error = nil; 
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { 
    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
      localizedReason:@"Please verify that you are the device owner in order to place the order" 
        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]; 
         } 
         }); 
        }]; 
} 

으로 메인 스레드에서 alertviews을 표시 할 수있는 다른, 당신은 UI의 일을 할 필요가 말했듯이 {

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

}

1

주 스레드에서 Swift 3.0의 경우 :

myContext.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: myLocalizedReasonString) { (success, evaluateError) in 
      DispatchQueue.main.async { 
        if (success) { 
         //success 
        } else { 
         //failure 
        } 
       } 
      }