首页 > 解决方案 > 快速在 UIDocumentPicker 中设置文档扩展名

问题描述

我正在使用文档选择器来选择文档并上传到服务器。我只需要为允许的文档传递一些扩展名,但是我无法找出扩展名代表什么类型的文档。这是我想要允许的扩展列表。- docx - Microsoft Word - xlsx - Microsoft Excel - pptx - Microsoft Powerpoint - pdf - csv - pages - numbers - key - Keynote - rtf - txt 我知道一些扩展名,例如“kUTTypePDF,kUTTypeRTF”,但不是所有的都请帮忙。

标签: iosswiftuikit

解决方案


斯威夫特 5.0

let types = [kUTTypePDF, kUTTypeText, kUTTypeRTF, kUTTypeSpreadsheet] // You can add more types here as pr your expectation
let importMenu = UIDocumentPickerViewController(documentTypes: types as [String], in: .import)

试试这个

如果要选择所有文件,则必须使用以下代码:

let documentPicker = UIDocumentPickerViewController(documentTypes: ["com.apple.iwork.pages.pages", "com.apple.iwork.numbers.numbers", "com.apple.iwork.keynote.key","public.image", "com.apple.application", "public.item", "public.content", "public.audiovisual-content", "public.movie", "public.audiovisual-content", "public.video", "public.audio", "public.text", "public.data", "public.zip-archive", "com.pkware.zip-archive", "public.composite-content"], in: .import)

推荐阅读