Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doc file issues with UIDocumentPickerController in iOS swift?

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 ?

like image 828
TechChain Avatar asked Sep 13 '17 11:09

TechChain


2 Answers

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

like image 179
Mahendra Avatar answered Nov 01 '22 01:11

Mahendra


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

like image 6
Sneha Avatar answered Nov 01 '22 00:11

Sneha