使用 UIDocumentPickerViewController,是否可以像在 Slack 中一样在第一次打开时显示默认服务(Dropbox、Google Drive 等)?

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

通常,UIDocumentPicker 的行为是您呈现,然后用户必须使用右上角的"Locations" 菜单在服务之间切换。是否可以默认先显示"Dropbox"或"Google Drive"?几乎就像我们 "deeplinking" 进入 UIDocumentPicker 服务一样。

似乎 Slack 应用程序和 MyMail 应用程序都能做到这一点,但我找不到 API。有什么想法吗?

这与 Google Drive 无关,但在过去的工作中,当 Apple SDK 未向我显示 Facebook 时,我需要显示 Facebook。 (这里的极端情况是用户的 Facebook 帐户不在“设置”中。)

所以我抓住了他们的图标并制作了一个自定义条目。

我想你也可以在这里做同样的事情。抓住 Google 驱动器图标并将其设为自定义文档。当用户选择它时,您将它们交给 Google。

这只是一个猜测,因为我没有使用过 UIDocumentPicker。而且,它非常骇人听闻。

尝试使用 UIDocumentMenuViewController,而不是使用 UIDocumentPickerViewController。这是 relevant documentation.

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

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

默认情况下,这将显示包含文档提供程序扩展的应用程序(例如 Dropbox、Google Drive、iCloud 等)。因此,如果用户在其设备上安装了 Dropbox 或 Google Drive,这些选项将自动显示。

您还可以通过调用 addOptionWithTitle:image:order:handler: 方法向菜单添加自定义选项。

Swift 代码示例:

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)