访问_cachedSystemAnimationFence的NSInternalInconsistencyException需要主线程

nwk*_*ley 13 ios

对一些beta测试者使用Crittercism我看到一个错误出现了几次,我从来没有经历过我自己,我无法复制.

Crittercism告诉我:访问_cachedSystemAnimationFence的NSInternalInconsistencyException需要主线程

它指向的线是:

[picker dismissViewControllerAnimated:YES completion:^{
Run Code Online (Sandbox Code Playgroud)

在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];

            }];

        }];
    }];

}
Run Code Online (Sandbox Code Playgroud)

Ada*_*G J 28

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

dispatch_async(dispatch_get_main_queue(), ^{
    // Call UI related operations
});
Run Code Online (Sandbox Code Playgroud)


小智 4

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