xcode 我的应用程序在 UIDocumentPickerViewController 上崩溃了

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29300772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:53:01  来源:igfitidea点击:

My app is getting crashed on UIDocumentPickerViewController

iosxcodeicloudicloud-driveuidocumentpickervc

提问by Anand3777

I am working on file sharing on my iOS App, I am new to UIDocumentPickerViewController. I do not know why my app is crashing.

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

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

App is crashing on the highlighted lines.

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

Has anyone done this previously? I want to do the same like the attachment below enter image description here

有没有人以前做过这个?我想像下面的附件一样做同样的事情在此处输入图片说明

回答by Francesco Vadicamo

See Prerequisitesection on Apple Documentation:

请参阅Apple 文档Prerequisite部分:

Before your app can use the document picker, you must turn on the iCloud Documents capabilities in Xcode

在您的应用程序可以使用文档选择器之前,您必须在 Xcode 中打开 iCloud 文档功能

enter image description here

在此处输入图片说明

Let me know if this solve your problem!

如果这能解决您的问题,请告诉我!

回答by Harikant Amipara

swift 3.0you can select all document.

swift 3.0可以选择所有文档。

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)

回答by Nir Golan

Even with all entitlements set up, this still happens every now and then, when running on a device(not simulator).
The best solution I've found so far is:

即使设置了所有权利,在设备(不是模拟器)运行时,这种情况仍然时不时发生。
到目前为止,我发现的最佳解决方案是:

  1. Stop the app from Xcode.
  2. Launch the app from the device (tap the app icon on the home screen...)
  3. Navigate in your app, in order to open the UIDocumentPickerViewController.
  4. Once open, you can launch the app again in Xcode and UIDocumentPickerViewControllerwill init as intended.
  1. 从 Xcode 停止应用程序。
  2. 从设备启动应用程序(点击主屏幕上的应用程序图标...)
  3. 在您的应用中导航,以打开UIDocumentPickerViewController.
  4. 打开后,您可以在 Xcode 中再次启动该应用程序UIDocumentPickerViewController并按预期进行初始化。

From my experience, it will work until you install a TestFlight build. Sometimes you'll need to do this again after restarting Xcode.
This certainly looks like a bug with installing entitlements on the device.

根据我的经验,它会一直工作到您安装 TestFlight 版本。有时您需要在重新启动 Xcode 后再次执行此操作。
这当然看起来像是在设备上安装权利的错误。

(Xcode 7.2, iOS 9.2)

(Xcode 7.2,iOS 9.2)

回答by Ketan Patel

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