【问题标题】:Using the UIDocumentPickerViewController, is it possible to show a default service (Dropbox, Google Drive, etc) on first open like in Slack?使用 UIDocumentPickerViewController,是否可以像在 Slack 中一样在首次打开时显示默认服务(Dropbox、Google Drive 等)?
【发布时间】:2015-09-13 06:06:47
【问题描述】:

通常,UIDocumentPicker 的行为是您呈现,然后用户必须使用右上角的“位置”菜单在服务之间切换。默认情况下是否可以先显示“Dropbox”或“Google Drive”?几乎就像我们在“深度链接”到 UIDocumentPicker 服务一样。

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

【问题讨论】:

标签: ios objective-c ios8 icloud drive


【解决方案1】:

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)

【讨论】:

  • 谢谢;主要用于共享几乎所有内容的documentTypes 字符串:)
【解决方案2】:

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

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

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

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

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

【讨论】:

  • 嗨,我如何为“NewRecordingViewController”清除 UTI @interface 声明选择器“UTI”
  • 仅供参考:UIDocumentMenuViewController 在 iOS 11 中已弃用
  • iOS 11 中 UIDocumentMenuViewController 的任何替代方案?我真的需要展示实际菜单,而不是转到最近的位置,然后从那里转到“位置”?
  • 看来,正如@user1210182 和@Bharath 所说,UIDocumentMenuViewController 现在已被弃用。但似乎也没有办法向UIDocumentPickerViewController 添加自定义选项,例如访问本地文件或摄像头。我对吗?或者有没有办法将此功能添加到UIDocumentPickerViewController?
  • @ainsausti 我没有在 DocumentPicker 中找到方法。 Apple 真的不酷,如果我们想提供更多选项而不仅仅是文件,他们希望我们用一个 pre-actionSheet 替换文件/图片选择器菜单,这会导致 DocumentPicker。
【解决方案3】:

这不是专门针对 Google Drive,而是在过去的工作中,当 Apple SDK 没有向我显示 Facebook 时,我需要显示 Facebook。 (这里的边缘情况是用户的 Facebook 帐户不在“设置”中。)

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

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

这只是一个猜测,因为我没有使用 UIDocumentPicker。而且,它非常hackish。

【讨论】:

    猜你喜欢
    • 2016-08-31
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    相关资源
    最近更新 更多