使用UIDocumentPickerViewController,可以像在Slack中一样打开默认服务(Dropbox,Google Drive等)吗?

通常情况下,UIDocumentPicker的行为就是您提供的,那么用户必须使用右上angular的“位置”菜单在服务之间切换。 默认情况下可以首先显示“Dropbox”或“Google Drive”吗? 几乎就像我们“深入”到UIDocumentPicker服务。

看起来像Slack App能够做到这一点,也是MyMail应用程序,但我无法find它的API。 有任何想法吗?

松弛的应用程序

而不是使用UIDocumentPickerViewController,请尝试使用UIDocumentMenuViewController。 这里是相关的文件 。

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) 

这不是专门针对Google云端硬盘,而是以前的工作,当Apple SDK没有向我展示Facebook时,我需要展示Facebook。 (这里的边缘情况是用户的Facebook帐户不在设置中。)

所以我抓住他们的图标,并进行了自定义条目。

我怀疑你可以在这里做同样的事情。 抓住Google Drive图标并制作一个自定义文档。 而当用户select它,你把它们交给谷歌。

这只是一个猜测,因为我没有使用UIDocumentPicker。 而且,这是相当的黑客。

Interesting Posts