25

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

Vu Tran
  • 600
  • 2
  • 6
  • 14
  • **For Swift 4.X** You can find answer here. https://stackoverflow.com/questions/33890225/how-to-access-files-in-icloud-drive-from-within-my-ios-app/50734896#50734896 – Ashu Jun 07 '18 at 07:16

3 Answers3

22

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.

keither04
  • 321
  • 2
  • 6
  • 1
    hi how can i declear UTIs @interface for 'NewRecordingViewController' declares the selector 'UTIs' – Nisar Ahmad Apr 05 '16 at 08:19
  • @keither04 in installed dropbox how can i fire particular method action on its click? – arpita Dec 01 '17 at 07:42
  • 11
    FYI: UIDocumentMenuViewController is deprecated in iOS 11 – Bharath Dec 26 '17 at 13:37
  • 2
    Any alternatives for UIDocumentMenuViewController in iOS 11? I really need to present the actual menu rather than going to most recent location then going to "Locations" from there? – user1210182 Jan 04 '18 at 17:14
  • @user1210182 The Apple developer documentation says you should use ```UIDocumentPickerViewController``` instead. So the menu picker and document picker are now integrated into one menu (it seems). – Supertecnoboff Feb 01 '18 at 10:15
  • 3
    It seems, as @user1210182 and @Bharath have said, that the `UIDocumentMenuViewController` is deprecated now. But it also seems that there is no way to add custom options to the `UIDocumentPickerViewController` such as accessing to local files or the camera. Am I right? or is there a method to add this functionality to `UIDocumentPickerViewController`? – ainsausti Mar 09 '18 at 10:11
  • 1
    @ainsausti I didn't find a method in DocumentPicker. It's really not cool from Apple, they want us to replace file/picture picker menus by an pre-actionSheet that lead to DocumentPicker if we want to offer more options than just files. – Gonzo Oin Mar 28 '18 at 20:19
8

Swift code example:

let documentProvider = UIDocumentMenuViewController(documentTypes: ["public.image", "public.audio", "public.movie", "public.text", "public.item", "public.content", "public.source-code"], in: .import) 
documentProvider.delegate = self

self.present(documentProvider, animated: true, completion: nil)
1

This isn't specifically about Google Drive but at a past job I needed to display Facebook when Apple SDK wasn't showing me Facebook. (The edge case here was the user's Facebook account wasn't in Settings.)

So I grabbed their icon and made a custom entry.

I suspect that you could do the same here. Grab the Google Drive icon and make that a custom Document. And when the user selects it, you hand them off to Google.

This is just a guess since I've not used UIDocumentPicker. And also, it is quite hackish.

Paul Cezanne
  • 8,629
  • 7
  • 59
  • 90