2

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!

1 Answer 1

7

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.