gpt4 book ai didi

ios - 在 Touch ID block 内调用 PerformSegue 后应用程序停止

转载 作者:行者123 更新时间:2023-11-29 02:33:14 26 4
gpt4 key购买 nike

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

我向用户出示触摸 ID 标识,如果他获得授权,我调用 [self performSegueWithIdentifier: @"callCustomSegue"sender:self];以这种方式在 block 内:

[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 block :

[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];
}

}];

点击确定后,立即调用下一个 ViewController。

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

知道我哪里错了吗?

非常感谢。

最佳答案

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

你应该有——

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

关于ios - 在 Touch ID block 内调用 PerformSegue 后应用程序停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26649876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com