2014-10-30 32 views
0

嗨我遇到了一個奇怪的行爲,我真的不明白。應用程序在調用performSegue裏面Touch ID塊後停止

我向用戶展示了一個觸摸ID標識,如果他被授權我調用[self performSegueWithIdentifier:@「callCustomSegue」sender:self]; 這樣塊內:

[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
        localizedReason:myLocalizedReasonString 
          reply:^(BOOL success, NSError *error) { 
           if (success) { 
            [self performSegueWithIdentifier: @"callCustomSegue" sender:self]; 

然後該應用停止若干秒(至少3-4)然後下一個的ViewController被呈現。

的執行由「callCustomSegue」叫做到這一點:

- (void) perform { 

    src = (UIViewController *) self.sourceViewController; 
    dst = (UIViewController *) self.destinationViewController; 

    [src.view addSubview:dst.view]; 

} 

我不明白髮生了什麼觸摸ID的識別和performSegueWithIdentifier 爲什麼應用程序停止之間發生的事情。

如果我忽略了touch ID,並且只是像我期望的那樣調用performSegueWithIdentifier立即工作。

如果我把在觸摸ID塊:

[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics 
        localizedReason:myLocalizedReasonString 
          reply:^(BOOL success, NSError *error) { 
           if (success) { 
        authenticated = YES; 
         [self showMessage:@"Authentication is successful" withTitle:@"Success"]; 
       } 

其中showMessage做到這一點:

UIAlertController * alert= [UIAlertController 
            alertControllerWithTitle:title 
            message:message 
            preferredStyle:UIAlertControllerStyleAlert]; 


    UIAlertAction* cancel = [UIAlertAction 
          actionWithTitle:@"OK" 
          style:UIAlertActionStyleDefault 
          handler:^(UIAlertAction * action) 
          { 
           [alert dismissViewControllerAnimated:YES completion:nil]; 

           if (authenticated) { 
            [self performSegueWithIdentifier: @"callCustomSegue" sender:self]; 
           } 

           if (!authenticated) { 
            [self touchID]; 
           } 

          }]; 

攻OK之後的下一個視圖控制器立即調用。

所以問題是:爲什麼我不能在touch ID塊中調用performSegue並獲得立即響應?

任何想法,我錯了嗎?

非常感謝。

回答

1

您應該在主隊列上執行所有UI相關的活動。 touchID進程的reply塊不保證在主隊列上執行。事實上,你幾乎可以保證它不會。

你應該有 -

if (success) { 
    authenticated = YES; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self performSegueWithIdentifier: @"callCustomSegue" sender:self]; 
    }); 
+0

感謝名單了這麼多,我只是學到新的東西給我。再次感謝你,完美無瑕。 – Fabrizio 2014-10-30 11:45:26

相關問題