4

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

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

4

3 回答 3

10

请尝试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
}
于 2018-02-18T12:11:19.317 回答
3

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

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

于 2020-02-14T09:20:34.383 回答
1

斯威夫特 5

let docsTypes = ["public.text",
                     "com.apple.iwork.pages.pages",
                     "public.data",
                     "kUTTypeItem",
                     "kUTTypeContent",
                     "kUTTypeCompositeContent",
                     "kUTTypeData",
                     "public.database",
                     "public.calendar-event",
                     "public.message",
                     "public.presentation",
                     "public.contact",
                     "public.archive",
                     "public.disk-image",
                     "public.plain-text",
                     "public.utf8-plain-text",
                     "public.utf16-external-plain-​text",
                     "public.utf16-plain-text",
                     "com.apple.traditional-mac-​plain-text",
                     "public.rtf",
                     "com.apple.ink.inktext",
                     "public.html",
                     "public.xml",
                     "public.source-code",
                     "public.c-source",
                     "public.objective-c-source",
                     "public.c-plus-plus-source",
                     "public.objective-c-plus-​plus-source",
                     "public.c-header",
                     "public.c-plus-plus-header",
                     "com.sun.java-source",
                     "public.script",
                     "public.assembly-source",
                     "com.apple.rez-source",
                     "public.mig-source",
                     "com.apple.symbol-export",
                     "com.netscape.javascript-​source",
                     "public.shell-script",
                     "public.csh-script",
                     "public.perl-script",
                     "public.python-script",
                     "public.ruby-script",
                     "public.php-script",
                     "com.sun.java-web-start",
                     "com.apple.applescript.text",
                     "com.apple.applescript.​script",
                     "public.object-code",
                     "com.apple.mach-o-binary",
                     "com.apple.pef-binary",
                     "com.microsoft.windows-​executable",
                     "com.microsoft.windows-​dynamic-link-library",
                     "com.sun.java-class",
                     "com.sun.java-archive",
                     "com.apple.quartz-​composer-composition",
                     "org.gnu.gnu-tar-archive",
                     "public.tar-archive",
                     "org.gnu.gnu-zip-archive",
                     "org.gnu.gnu-zip-tar-archive",
                     "com.apple.binhex-archive",
                     "com.apple.macbinary-​archive",
                     "public.url",
                     "public.file-url",
                     "public.url-name",
                     "public.vcard",
                     "public.image",
                     "public.fax",
                     "public.jpeg",
                     "public.jpeg-2000",
                     "public.tiff",
                     "public.camera-raw-image",
                     "com.apple.pict",
                     "com.apple.macpaint-image",
                     "public.png",
                     "public.xbitmap-image",
                     "com.apple.quicktime-image",
                     "com.apple.icns",
                     "com.apple.txn.text-​multimedia-data",
                     "public.audiovisual-​content",
                     "public.movie",
                     "public.video",
                     "com.apple.quicktime-movie",
                     "public.avi",
                     "public.mpeg",
                     "public.mpeg-4",
                     "public.3gpp",
                     "public.3gpp2",
                     "public.audio",
                     "public.mp3",
                     "public.mpeg-4-audio",
                     "com.apple.protected-​mpeg-4-audio",
                     "public.ulaw-audio",
                     "public.aifc-audio",
                     "public.aiff-audio",
                     "com.apple.coreaudio-​format",
                     "public.directory",
                     "public.folder",
                     "public.volume",
                     "com.apple.package",
                     "com.apple.bundle",
                     "public.executable",
                     "com.apple.application",
                     "com.apple.application-​bundle",
                     "com.apple.application-file",
                     "com.apple.deprecated-​application-file",
                     "com.apple.plugin",
                     "com.apple.metadata-​importer",
                     "com.apple.dashboard-​widget",
                     "public.cpio-archive",
                     "com.pkware.zip-archive",
                     "com.apple.webarchive",
                     "com.apple.framework",
                     "com.apple.rtfd",
                     "com.apple.flat-rtfd",
                     "com.apple.resolvable",
                     "public.symlink",
                     "com.apple.mount-point",
                     "com.apple.alias-record",
                     "com.apple.alias-file",
                     "public.font",
                     "public.truetype-font",
                     "com.adobe.postscript-font",
                     "com.apple.truetype-​datafork-suitcase-font",
                     "public.opentype-font",
                     "public.truetype-ttf-font",
                     "public.truetype-collection-​font",
                     "com.apple.font-suitcase",
                     "com.adobe.postscript-lwfn​-font",
                     "com.adobe.postscript-pfb-​font",
                     "com.adobe.postscript.pfa-​font",
                     "com.apple.colorsync-profile",
                     "public.filename-extension",
                     "public.mime-type",
                     "com.apple.ostype",
                     "com.apple.nspboard-type",
                     "com.adobe.pdf",
                     "com.adobe.postscript",
                     "com.adobe.encapsulated-​postscript",
                     "com.adobe.photoshop-​image",
                     "com.adobe.illustrator.ai-​image",
                     "com.compuserve.gif",
                     "com.microsoft.bmp",
                     "com.microsoft.ico",
                     "com.microsoft.word.doc",
                     "com.microsoft.excel.xls",
                     "com.microsoft.powerpoint.​ppt",
                     "com.microsoft.waveform-​audio",
                     "com.microsoft.advanced-​systems-format",
                     "com.microsoft.windows-​media-wm",
                     "com.microsoft.windows-​media-wmv",
                     "com.microsoft.windows-​media-wmp",
                     "com.microsoft.windows-​media-wma",
                     "com.microsoft.advanced-​stream-redirector",
                     "com.microsoft.windows-​media-wmx",
                     "com.microsoft.windows-​media-wvx",
                     "com.microsoft.windows-​media-wax",
                     "com.apple.keynote.key",
                     "com.apple.keynote.kth",
                     "com.truevision.tga-image",
                     "com.sgi.sgi-image",
                     "com.ilm.openexr-image",
                     "com.kodak.flashpix.image",
                     "com.j2.jfx-fax",
                     "com.js.efx-fax",
                     "com.digidesign.sd2-audio",
                     "com.real.realmedia",
                     "com.real.realaudio",
                     "com.real.smil",
                     "com.allume.stuffit-archive",
                     "org.openxmlformats.wordprocessingml.document",
                     "com.microsoft.powerpoint.​ppt",
                     "org.openxmlformats.presentationml.presentation",
                     "com.microsoft.excel.xls",
                     "org.openxmlformats.spreadsheetml.sheet"]
    
    let documentPicker = UIDocumentPickerViewController(documentTypes: docsTypes, in: .import)
    documentPicker.delegate = self
    documentPicker.allowsMultipleSelection = true
    present(documentPicker, animated: true, completion: nil)
于 2022-01-29T15:51:03.423 回答