Using the UIDocumentPickerViewController, is it possible to show a default service (Dropbox, Google Drive, etc) on first open like in Slack?
Solution 1
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.
Solution 2
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)
Solution 3
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.
Related videos on Youtube
Vu Tran
Updated on September 23, 2022Comments
-
Vu Tran over 1 year
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?
-
Ashu almost 6 yearsFor Swift 4.X You can find answer here. stackoverflow.com/questions/33890225/…
-
-
Nisar Ahmad about 8 yearshi how can i declear UTIs @interface for 'NewRecordingViewController' declares the selector 'UTIs'
-
Ivan Cantarino almost 7 yearsthanks; mostly for sharing the
documentTypes
strings for almost all the content :) -
arpita over 6 years@keither04 in installed dropbox how can i fire particular method action on its click?
-
Bharath over 6 yearsFYI: UIDocumentMenuViewController is deprecated in iOS 11
-
user1210182 over 6 yearsAny 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?
-
Supertecnoboff over 6 years@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). -
ainsausti about 6 yearsIt 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 theUIDocumentPickerViewController
such as accessing to local files or the camera. Am I right? or is there a method to add this functionality toUIDocumentPickerViewController
? -
Gonzo Oin about 6 years@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.