I am using below code for showing the document picker.When i show the picker i use below code
let documentPickerController = UIDocumentPickerViewController(documentTypes: [String(kUTTypeText), String(kUTTypePDF), String(kUTTypePNG), String(kUTTypeJPEG), String(kUTTypePlainText), String(kUTTypeImage)], in: .import)
Above code shows me the all files in my iCloud but it does not let me select the doc,docx files.These files appear as disabled.
But when i addd "public.data"
as element in UIDocumentPickerViewController
constructor then it is allowing me select doc,docx file & file does not appear as disabled.
Please tell me why this is happening ?
Just posting answer to help other user for this.
To choose .docx
file via document picker you need to use org.openxmlformats.wordprocessingml.document
type.
let documentPickerController = UIDocumentPickerViewController(documentTypes: ["com.microsoft.word.doc", "org.openxmlformats.wordprocessingml.document"], in: .import)
For iOS 14.0+
let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.appleArchive])
Thanks for the update @sadegh bitarafan
To be able to select doc and docx, you have to use public.data.
com.microsoft.word.doc conforms to public.data
kUTTypePlainText only allows files of .txt type
To allow only doc give "com.microsoft.word.doc
"
let documentPickerController = UIDocumentPickerViewController(documentTypes: [com.microsoft.word.doc], in: .import)
For more information: System-Declared Uniform Type Identifiers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With