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

iPhone App Crash with error [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:]

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

IOS10.1 发布后,当我查看崩溃报告时,崩溃次数增加了。从崩溃报告来看,它指向 [UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:],当我在 Xcode 中打开应用程序时,它专注于 [self dismissViewControllerAnimated:YES completion:nil];

我写的代码如下:

-(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 相关的事情都必须在主线程上完成(包括关闭视图控制器)。

我建议像这样在主线程块上添加关闭行:

-(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 {
   }];
    }

}