【问题标题】:How to open native files app in ios?如何在 ios 中打开本机文件应用程序?
【发布时间】:2018-07-28 19:22:42
【问题描述】:

如何使用 url 方案或其他方式打开 ios 的本机文件应用程序? 我尝试搜索 url 方案但没有运气。

这个问题似乎没有答案,苹果论坛中有这个问题的帖子,但仍然没有答案。 https://forums.developer.apple.com/message/257860#257860 可以使用捆绑标识符来完成吗?

【问题讨论】:

  • 为什么需要打开应用程序?你想达到什么目标?
  • 让用户选择要分享的文件和文档!
  • 我的回答解决了你的问题吗?
  • 不,如果您查看现有应用程序,他们所做的只是使用文件应用程序让用户选择文档我也想做同样的事情,所以请您帮忙!
  • 恕我直言,每个人都通过“UIDocumentPickerViewController”访问“文件”应用程序中的数据。我在答案中发布的代码允许您打开一个 ViewController,它向您显示与 Files 应用程序中相同的文件。你试过我的代码了吗?

标签: ios swift ios-urlsheme files-app


【解决方案1】:

请尝试在您的用例中使用UIDocumentPickerViewController

let controller = UIDocumentPickerViewController(
    documentTypes: ["public.text"], // choose your desired documents the user is allowed to select
    in: .import // choose your desired UIDocumentPickerMode
)
controller.delegate = self
if #available(iOS 11.0, *) {
    controller.allowsMultipleSelection = false
}
// e.g. present UIDocumentPickerViewController via your current UIViewController
present(
    controller,
    animated: true,
    completion: nil
)

UIDocumentPickerDelegate 委托方法接收所选文档 URL 作为回调:

@available(iOS 11.0, *)
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
    // do something with the selected documents
}

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    // do something with the selected document
}

【讨论】:

【解决方案2】:

可以选择使用shareddocuments:// URL 方案在特定位置打开“文件”应用,如this article 中所述。

如果您希望用户选择一个文档,您可以使用chriswillow's 方法和UIDocumentPickerViewController。 如果您想在您的应用中展示文档或文件夹,请创建一个Document Browser App

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多