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
My app is getting crashed on UIDocumentPickerViewController
提问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
有没有人以前做过这个?我想像下面的附件一样做同样的事情
回答by Francesco Vadicamo
See Prerequisite
section 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 文档功能
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:
即使设置了所有权利,在设备(不是模拟器)上运行时,这种情况仍然时不时发生。
到目前为止,我发现的最佳解决方案是:
- Stop the app from Xcode.
- Launch the app from the device (tap the app icon on the home screen...)
- Navigate in your app, in order to open the
UIDocumentPickerViewController
. - Once open, you can launch the app again in Xcode and
UIDocumentPickerViewController
will init as intended.
- 从 Xcode 停止应用程序。
- 从设备启动应用程序(点击主屏幕上的应用程序图标...)
- 在您的应用中导航,以打开
UIDocumentPickerViewController
. - 打开后,您可以在 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];