5

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 ?

pacification
  • 5,838
  • 4
  • 29
  • 51
TechChain
  • 8,404
  • 29
  • 103
  • 228

3 Answers3

8

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

Mahendra
  • 8,448
  • 3
  • 33
  • 56
6

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

Sneha
  • 2,200
  • 6
  • 22
  • 36
1

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]
FlimFlam Vir
  • 1,080
  • 9
  • 15