【问题标题】:App stops after calling performSegue inside Touch ID block在 Touch ID 块内调用 performSegue 后应用停止
【发布时间】:2014-10-30 09:56:10
【问题描述】:

您好,我遇到了一种我真的不明白的奇怪行为。

我向用户出示 Touch 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];

}

我不明白 touch 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。

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

知道我哪里错了吗?

非常感谢。

【问题讨论】:

    标签: ios uistoryboardsegue touch-id


    【解决方案1】:

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

    你应该有 -

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

    【讨论】:

    • 非常感谢,我刚刚学到了一些新东西。再次感谢您,完美运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多