如何在iOS中打开本机文件应用程序?

Nik*_*nju 0 ios swift ios-urlsheme files-app

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

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

小智 6

可以选择使用 URL 方案在特定位置打开文件应用程序,如本文shareddocuments://所述。

如果您希望用户选择一个文档,您可以将chriswillow 的方法与UIDocumentPickerViewController结合使用。如果您想在应用程序中呈现文档或文件夹,请创建一个文档浏览器应用程序


chr*_*low 5

请尝试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
)
Run Code Online (Sandbox Code Playgroud)

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
}
Run Code Online (Sandbox Code Playgroud)

  • 对于“documentTypes”,这里有一个[“系统声明的统一类型标识符”](https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html# //apple_ref/doc/uid/TP40009259),希望对其他人有帮助。 (2认同)