iPhone 应用程序崩溃并出现错误 [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary :]

标签 iphone uiviewcontroller objective-c-blocks touch-id

我在应用程序商店中有一个使用 Touch ID 的 iPhone 应用程序。如果启用了 Touch ID,则用户将通过它进行身份验证,否则用户需要输入 PIN 码才能登录应用程序。

iOS 10.1发布后,当我检查崩溃报告时,崩溃次数有所增加。从崩溃报告来看,它指向 [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] ,当我在 Xcode 中打开应用程序时,它的重点是 [selfmissViewControllerAnimated:YES finish:nil];.

Crash Report

我编写的代码如下:

-(void) showTouchIDAuthentication{

    LAContext *myContext = [[LAContext alloc] init];
    NSError *authError = nil;
    NSString *myLocalizedReasonString = @"Authenticate using your finger to access My Account Menu.";
    if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
        [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
                  localizedReason:myLocalizedReasonString
                            reply:^(BOOL success, NSError *error) {
                                if (success) {
                                    NSLog(@"User is authenticated successfully");
                                    [self dismissViewControllerAnimated:YES completion:nil];
                                } else {
   }];
    }

}

当我在 iPhone 6、IOS 10 中测试时,一切正常。不知道如何模拟该问题。

任何人都可以弄清楚我是否遗漏了什么吗?请帮我解决这个崩溃问题。

最佳答案

通常完成处理程序不在主线程上运行。所有与 UI 相关的操作都必须在主线程上完成(包括关闭 View Controller )。

我建议在主线程 block 上添加解雇行,如下所示:

-(void) showTouchIDAuthentication{

LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
NSString *myLocalizedReasonString = @"Authenticate using your finger to access My Account Menu.";
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
    [myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
              localizedReason:myLocalizedReasonString
                        reply:^(BOOL success, NSError *error) {
                            if (success) {
                                NSLog(@"User is authenticated successfully");

                                [[NSOperationQueue mainQueue] addOperationWithBlock:^ {
                                    [self dismissViewControllerAnimated:YES completion:nil];
                                }];

                            } else {
   }];
    }

}

关于iPhone 应用程序崩溃并出现错误 [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary :],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39695328/

相关文章:

ios - UISearchBar:更改输入字段的背景颜色

iphone - 检测用户何时开始录像

ios - App进入后台判断当前ViewController

ios - swift4:关闭当前 View Controller 并显示另一个没有 navigationController 的 Controller

Objective-c: block 和 NSEnumerationConcurrent 的问题

iOS >> block >> 更改 block 外部变量的值

iphone - 将 UIAppearance 与 UIBarButtonItem 的子类一起使用会导致无法识别的选择器被发送到 UINavigationButton

iphone - UIViewController - UIModalPresentationCurrentContext 不旋转 presentingViewController

ios - 带有完成 block 的 NSOperation

iPhone RestKit 如何启用 RKLogDebug?