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
以前有人这样做过吗?我想做的和下面的附件一样
4 个解决方案
#1
37
See Prerequisite
section on Apple Documentation:
有关苹果文档的前提部分:
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!
如果这能解决你的问题,请告诉我!
#2
3
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.
- 停止应用程序Xcode。
- Launch the app from the device (tap the app icon on the home screen...)
- 从设备上启动app(点击主屏幕上的app图标…)
- Navigate in your app, in order to open the
UIDocumentPickerViewController
. - 在app中导航,以打开UIDocumentPickerViewController。
- Once open, you can launch the app again in Xcode and
UIDocumentPickerViewController
will init as intended. - 一旦打开,你可以在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)
#3
2
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.apple.iwork.pages.pages", @"com.apple.iwork.numbers.numbers", @"com.apple.iwork.keynote.key"] inMode:UIDocumentPickerModeImport];
#4
1
swift 3.0 you can select all document.
您可以选择所有的文档。
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)
#1
37
See Prerequisite
section on Apple Documentation:
有关苹果文档的前提部分:
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!
如果这能解决你的问题,请告诉我!
#2
3
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.
- 停止应用程序Xcode。
- Launch the app from the device (tap the app icon on the home screen...)
- 从设备上启动app(点击主屏幕上的app图标…)
- Navigate in your app, in order to open the
UIDocumentPickerViewController
. - 在app中导航,以打开UIDocumentPickerViewController。
- Once open, you can launch the app again in Xcode and
UIDocumentPickerViewController
will init as intended. - 一旦打开,你可以在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)
#3
2
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.apple.iwork.pages.pages", @"com.apple.iwork.numbers.numbers", @"com.apple.iwork.keynote.key"] inMode:UIDocumentPickerModeImport];
#4
1
swift 3.0 you can select all document.
您可以选择所有的文档。
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)