迅速在UIDocumentPicker中设置文档扩展名

时间:2018-08-29 06:34:46

标签: ios swift uikit

我正在使用文档选择器来选择文档并在服务器上上传。我需要为允许的文档传递一些扩展名,但是我无法找出什么扩展名代表什么类型的文档。这是我要允许的扩展列表。         -docx-Microsoft Word         -xlsx-Microsoft Excel         -pptx-Microsoft Powerpoint         -pdf         -CSV         -页         -数字         -关键-主题演讲         -rtf         - 文本文件 我知道一些扩展名,例如“ kUTTypePDF,kUTTypeRTF”,但并非所有人都可以帮助。

3 个答案:

答案 0 :(得分:1)

尝试这个

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

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)

答案 1 :(得分:0)

Apple has posted a list of the built-in document types here:

https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

I believe that should have all the ones you are looking for. If not, then you'll have to add your own types. You can do this by selecting the Project in Xcode and going into the Info tab. Then at the bottom, add a new Imported UTI for each file type.

  • Description: User-friendly description
  • Identifier: This is the identifier you will use in the documentTypes parameter for UIDocumentPickerViewController. com.yourcompany.yourproduct.fileextension or similar.
  • Conforms to: "public.data, public.content"

Then under Additional Imported UTI properties click to add the following:

UTTypeTagSpecification (Dictionary)
    public.filename-extension (Array)
        Item 0 (String): the file extension without "." (i.e. "csv")

答案 2 :(得分:0)

对于 .doc .docx ,您可以使用“ com.microsoft.word.doc” “组织。 openxmlformats.wordprocessingml.document”

对于 .xlsx ,您可以使用“ org.openxmlformats.spreadsheetml.sheet”

对于 .xls ,您可以使用“ com.microsoft.excel.xls”