iCloud UIDocumentPicker 间歇性崩溃并卡住。

10

问题:

从iCloud中选择文档时,该应用程序会随机崩溃。大多数情况下以下代码将起作用,但在极少数情况下会失败。

我已经在应用程序中启用了iCloud授权,但似乎找不到它间歇性失败的原因。我是否遗漏了某个检查?

有时还会出现明显的5秒钟左右挂起(通常是在崩溃之前)

代码:

#pragma mark - iCloud =======================================================================================================
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {

BOOL fileUrlAuthozied = [url startAccessingSecurityScopedResource];
NSURL *ubiquityURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
NSLog(@"ubiquityURL - %@",ubiquityURL);

if(fileUrlAuthozied){
    NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
    NSError *error;

    [fileCoordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {

        NSData *data = [NSData dataWithContentsOfURL:newURL];
        //Do something with data
        selectedDocumentToUpload = [[UploadDocumentObj alloc] initWithiCloudDocument:data];
        [self performSegueWithIdentifier:@"goToRename" sender:nil];

    }];
    [url stopAccessingSecurityScopedResource];
}else{
     //Error handling
    [Lib showErrorMessageWithTitle:@"Alert" message:@"E-Sign could not retrive the document!\nPlease try again." delegate:self];

}
}

错误:

2015-03-18 16:22:15.955 E-Sign[6338:1860982] *** Assertion failure in -[UIDocumentPickerViewController _commonInitWithCompletion:], /SourceCache/UIKit/UIKit-3318.93/UIDocumentPickerViewController.m:66
2015-03-18 16:22:15.960 E-Sign[6338:1860982] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?'

其他错误:

2015-03-18 16:33:45.884 E-Sign[6357:1864309] plugin com.apple.UIKit.fileprovider.default interrupted
2015-03-18 16:33:45.885 E-Sign[6357:1864309] plugin com.apple.UIKit.fileprovider.default invalidated

有人遇到过这种情况吗?


我也遇到过这种情况,我不确定这是仅在开发中出现的问题,还是在生产环境中也会发生。 - Nir Golan
它在两者中都发生。外部测试人员不断报告相同的问题,最后由于其不可靠性我删除了整个iCloud功能。 - AJ9
4个回答

10

我最近遇到了相同的问题:

-[UIDocumentPickerViewController _commonInitWithCompletion:]中的***断言失败

这是因为缺少应用程序能力所致。 在构建中选择 Capabilities -> iCloud

通过右侧的开关激活它,并切换 iCloud 文档CloudKit 开启。(注意:这仅适用于付费的开发者帐户)

重新构建->运行

还要注意以下内容:

iCloud 权限仅适用于提交到 App Store 或 Mac App Store 的应用程序。(来源)


2
使用UIDocumentPickerViewController时遇到了相同的问题。在iOS 9/10中,应用程序需要iCloud功能。从iOS开始不再需要... - heyfrank

0

看起来出现了iCloud权限设置错误,请再次检查。您的容器应用程序和扩展程序需要在相同的应用组中。如果未启用,请从功能中启用应用程序组。如果两者都已正确设置,但仍然出现错误,则不知道错误可能发生在何处。

2015-03-18 16:22:15.960 E-Sign[6338:1860982] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?'

我也遇到了其他错误,这就是我来这里的原因。


如原来的问题所讨论的那样,iCloud 权限已经被启用。错误间歇性发生是一个问题。 - AJ9

0
经过大量研究,我得出了一个重要的结论:
我遇到了同样的问题,这真的很伤人。因此,在深入检查代码并调试后,最终的结果是管理您在显示Picker时执行的UI更改。显示Picker和UI更改的转换会产生恼人的行为,最终导致崩溃和挂起。
所以我的建议是尽量减少UI更新,并在后台进行这些更改,以使Picker的打开无缝。
在进行这些更改后,我的问题得到了解决。

-1
在调用该方法时,请确保在后台线程中调用它。这将解决问题。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{ // 调用你的方法 });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接