我的应用程序正在UIDocumentPickerViewController上崩溃

我正在处理我的iOS应用程序上的文件共享,我是UIDocumentPickerViewController 。 我不知道为什么我的应用程序崩溃。

 UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.image"] inMode:UIDocumentPickerModeImport]; documentPicker.delegate = self; documentPicker.modalPresentationStyle = UIModalPresentationFormSheet; [self presentViewController:documentPicker animated:YES completion:nil]; 

应用程序在突出显示的行上崩溃。

有没有人以前做过? 我想要像下面的附件一样做 在这里输入图像说明

请参阅Apple文档的 Prerequisite部分:

在您的应用程序可以使用文档select器之前,您必须打开Xcode中的iCloud Documentsfunction

在这里输入图像说明

让我知道这是否解决您的问题!

即使设置了所有权利,在设备 (而不是模拟器) 运行时,仍会不时发生。
到目前为止我发现的最好的解决scheme是:

  1. 停止从Xcode的应用程序。
  2. 从设备启动应用程序(点击主屏幕上的应用程序图标…)
  3. 在您的应用程序中导航,以打开UIDocumentPickerViewController
  4. 一旦打开,您可以在Xcode中再次启动应用程序, UIDocumentPickerViewController将按预期启动。

从我的经验来看,它会工作,直到你安装TestFlight构build。 有时你需要在重新启动Xcode之后再次执行此操作。
这当然看起来像在设备上安装授权的错误。

(Xcode 7.2,iOS 9.2)

 UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.apple.iwork.pages.pages", @"com.apple.iwork.numbers.numbers", @"com.apple.iwork.keynote.key"] inMode:UIDocumentPickerModeImport]; 

swift 3.0可以select所有文件。

 let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.apple.iwork.keynote.key","public.image", "com.apple.application", "public.item","public.data", "public.content", "public.audiovisual-content", "public.movie", "public.audiovisual-content", "public.video", "public.audio", "public.text", "public.data", "public.zip-archive", "com.pkware.zip-archive", "public.composite-content", "public.text"], in: .import) documentPicker.delegate = self present(documentPicker, animated: true, completion: nil)