Using the UIDocumentPickerViewController, is it possible to show a default service (Dropbox, Google Drive, etc) on first open like in Slack?

Vu Tran picture Vu Tran · Jun 26, 2015 · Viewed 17k times · Source

Normally, the behavior with UIDocumentPicker is that you present, then the user must use the "Locations" menu on the top right to switch between the services. Is it possible to display either "Dropbox" or "Google Drive" first by default? Almost as if we're "deeplinking" into the UIDocumentPicker service.

It seems like Slack App is able to do this and also the MyMail App but I wasn't able to find an API for it. Any ideas?

Slack App

Answer

keither04 picture keither04 · Jul 22, 2015

Instead of using a UIDocumentPickerViewController, try using a UIDocumentMenuViewController. Here is the relevant documentation.

UIDocumentMenuViewController *documentProviderMenu =
[[UIDocumentMenuViewController alloc] initWithDocumentTypes:[self UTIs]
                                                     inMode:UIDocumentPickerModeImport];

documentProviderMenu.delegate = self;
[self presentViewController:documentProviderMenu animated:YES completion:nil];

By default, this will display apps that include a Document Provider extension (such as Dropbox, Google Drive, iCloud, etc.). So if a user has Dropbox or Google Drive installed on their device, these options would show up automatically.

You can also add custom options to the menu by calling the addOptionWithTitle:image:order:handler: method.