在Touch ID块中调用performSegue后,应用程序停止

时间:2014-10-30 09:56:10

标签: ios uistoryboardsegue touch-id

嗨,我正在经历一种我真的不明白的奇怪行为。

我向用户提供了一个触摸ID标识,如果他是我的授权 打电话给[self performSegueWithIdentifier:@" callCustomSegue"发件人:自]; 以这种方式在块内:

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

然后app停止几秒钟(至少3-4秒),然后显示下一个ViewController。

“callCustomSegue”调用的表演执行此操作:

- (void) perform {

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

    [src.view addSubview:dst.view];

}

我不明白触摸ID上的识别和performSegueWithIdentifier之间发生了什么 以及应用停止的原因。

如果我绕过触控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后立即调用下一个ViewController。

所以问题是:为什么我不能在触摸ID块中调用performSegue并立即得到响应?

知道我哪里错了吗?

非常感谢你。

1 个答案:

答案 0 :(得分:1)

您应该在主队列上执行所有与UI相关的活动。不保证在主队列上执行touchID进程的reply块。事实上,你几乎可以保证它不会成为。

你应该 -

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