5

我使用下面的代码来显示文档选择器。当我显示选择器时,我使用下面的代码

let documentPickerController = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText), String(kUTTypePDF), String(kUTTypePNG), String(kUTTypeJPEG), String(kUTTypePlainText), String(kUTTypeImage)], in: .import)

上面的代码向我显示了 iCloud 中的所有文件,但它不允许我选择 doc、docx 文件。这些文件显示为已禁用。

但是当我"public.data"在构造函数中添加为元素时,UIDocumentPickerViewController它允许我选择 doc,docx 文件和文件不会显示为禁用。

请告诉我为什么会这样?

4

3 回答 3

6

只需发布答案以帮助其他用户。

.docx通过文档选择器选择文件,您需要使用org.openxmlformats.wordprocessingml.document类型。

let documentPickerController = UIDocumentPickerViewController(documentTypes: ["com.microsoft.word.doc", "org.openxmlformats.wordprocessingml.document"], in: .import)

适用于 iOS 14.0+

let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.appleArchive])

感谢@sadegh bitarafan 的更新

于 2018-07-04T08:30:34.063 回答
6

为了能够选择 doc 和 docx,您必须使用 public.data。

com.microsoft.word.doc 符合 public.data

kUTTypePlainText 只允许 .txt 类型的文件

只允许 doc 给 " com.microsoft.word.doc"

let documentPickerController = UIDocumentPickerViewController(documentTypes: [com.microsoft.word.doc], in: .import)

更多信息:系统声明的统一类型标识符

于 2017-09-13T12:25:18.763 回答
1

对一堆类型的更多帮助:

let types = [kUTTypePDF, kUTTypeText, kUTTypeRTF, kUTTypeSpreadsheet, kUTTypePNG, kUTTypeJPEG, kUTTypeGIF, "com.microsoft.word.doc" as CFString, "org.openxmlformats.wordprocessingml.document" as CFString]
于 2019-04-06T20:56:10.207 回答