Doc file issues with UIDocumentPickerController in iOS swift?

3.9k views Asked by At

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 ?

3

There are 3 answers

1
Sneha On

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

0
FlimFlam Vir On

More help for a bunch of types:

let types = [kUTTypePDF, kUTTypeText, kUTTypeRTF, kUTTypeSpreadsheet, kUTTypePNG, kUTTypeJPEG, kUTTypeGIF, "com.microsoft.word.doc" as CFString, "org.openxmlformats.wordprocessingml.document" as CFString]
2
Mahendra On

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