In my iOS app I'm opening a UIDocumentMenuViewController
. When I called it with the UIDocumentPickerModeImport
mode, everything works fine (all my iCloud entitlements are set up).
When I call it with the UIDocumentPickerModeExportToService
, however, the app crashes with this error:
Assertion failure in -[UIDocumentMenuViewController initWithDocumentTypes:inMode:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.6.22/UIDocumentMenuViewController.m:71
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIDocumentMenuViewController initWithDocumentTypes:inMode:] can only be called with mode Import or Open'
What am I doing wrong? Why can this only be called with the Import or Open modes?
My code:
UIDocumentMenuViewController *exportMenu = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:@[@"public.image"]
inMode:UIDocumentPickerModeExportToService];
exportMenu.delegate = self;
[self presentViewController:exportMenu animated:YES completion:nil];
This happens in the simulator and on two devices that I've tested (both running iOS 10).
Any help will be greatly appreciated!
I just found the answer: When wanting to export you need to use a different init method: initWithURL:inMode:
I wish the exception would be a little bit more helpful in this case :)