繁体   English   中英

NSInternalInconsistencyExceptionException访问_cachedSystemAnimationFence需要主线程

[英]NSInternalInconsistencyException accessing _cachedSystemAnimationFence requires the main thread

与某些Beta测试人员一起使用Crittercism时,我看到多次出现错误,这是我从未经历过的,并且无法复制。

批评告诉我:NSInternalInconsistencyExceptionException访问_cachedSystemAnimationFence需要主线程

它指向的行是:

[picker dismissViewControllerAnimated:YES completion:^{

在StackOverflow上进行一些阅读后,似乎应该在主线程上运行任何UI代码。 我遇到的错误是因为在后台线程上运行了dismissViewControllerAnimated吗?

奇怪为什么这个错误是相对随机的(即我无法重现)以及如何解决它。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    __block PHObjectPlaceholder *assetPlaceholder;

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

        PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];

        assetPlaceholder = changeRequest.placeholderForCreatedAsset;

    } completionHandler:^(BOOL success, NSError *error) {

        NSArray *photos = [[NSArray alloc] initWithObjects:assetPlaceholder.localIdentifier, nil];
        PHFetchResult *savedPhotos = [PHAsset fetchAssetsWithLocalIdentifiers:photos options:nil];

        [savedPhotos enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {

            NSMutableArray *images = self.event.eventAttachments;
            if (images) {
                [images addObject:asset];
            } else {
                images = [[NSMutableArray alloc]init];
                [images addObject:asset];
            }

            self.event.eventAttachments = images;

            [picker dismissViewControllerAnimated:YES completion:^{

                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:4];
                NSArray *indexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];

                [self.tblChildrenNotes beginUpdates];
                [self.tblChildrenNotes reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
                [self.tblChildrenNotes endUpdates];

            }];

        }];
    }];

}

如果需要在块内调用任何与UI相关的操作,请使用dispatch。 与UI交互的所有内容都必须在主线程上运行。 您可以在主线程之外运行与UI无关的其他任务,以提高性能。

dispatch_async(dispatch_get_main_queue(), ^{
    // Call UI related operations
});

恐怕我没有解决方案,但是我可以提供以相同方式崩溃的应用程序的详细信息。 我们正在使用Cordova平台来构建我们的应用程序。 仅当用户安装了Swype键盘时,才可能在iOS9(在我们的iPhone 6中为iOS9)中发生此崩溃。 当打开/关闭键盘以键入通过Cordova的InAppBrowser插件显示的文本字段时,我们会看到崩溃,并且仅在某些情况下会发生崩溃。 删除Swype应用程序可以使错误消失。 不幸的是,由于我们没有编写应用程序中涉及的任何objc,因此调试时很难。 祝好运!

对于Swift 3

    DispatchQueue.main.async(execute: {
       //UI Related Function
    });

对我来说,此解决方案在尝试以横向模式打开pdfViewer时已解决。

检查以确保您的completionHandler实际上在主线程而非其他线程上被调用。 这通常是导致此特定问题的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM