2014-12-03 117 views
2

我正在努力添加LocalAuthentication框架以允許用戶使用類似設備上的指紋進行身份驗證。一切工作正常,但是當用戶通過指紋進行身份驗證時,需要10-15秒才能執行正確的安全操作,這是典型的,還是在我對用戶進行身份驗證時出現了問題? 代碼:你如何提高LoginAuthentication的速度?

-(void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[NPSColor NPSBackgroundColor]]; 
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Register" style:UIBarButtonItemStylePlain target:self action:@selector(onRegisterTapped)]; self.navigationItem.rightBarButtonItem = anotherButton; 
LAContext *context = [[LAContext alloc] init]; 
NSError *error = nil; if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) { [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Login?" reply:BOOL success, NSError *error { 
         if (error) { 

         } 

         if (success) { 
         [self performSegueWithIdentifier:@"loginSeg" sender:self]; 

         } else { 

         } 

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

回答

2

所以這可能是執行賽格瑞擁有與應主要在主線程中執行的視圖操作做。我不太確定,但很可能是evaluatePolicy方法在後臺線程上執行。如果是這種情況,你會想把你的performSegue放在主線程上。

要做到這一點,使用:

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self performSegueWithIdentifier:@"loginSeg" sender:self]; 
}); 
+0

沒錯,就是這樣!謝謝,我甚至不認爲它可能爲我處理一些多線程。 – Nathan 2014-12-03 18:23:36

+0

隨時!很高興看到它幫助:) – 2014-12-04 18:12:55