使用Crittercism与一些测试人员时,我发现出现了一个错误,这个错误出现了多次,但我自己从未遇到过,也无法复制。
Crittercism告诉我:NSInternalInconsistencyException访问_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];
}];
}];
}];
}