2

I need the user to select only images and pdf files from UIDocumentPicker & want to check which type of file user has selected in the DocumentPicker delegate method

I have used this but this allow everything

let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.content","public.data"], in: .import)
Parth Soni
  • 67
  • 1
  • 6

2 Answers2

3

You can use

let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.composite-content"], in: .import)

this will only allow pdf files to import

Parth Dhorda
  • 712
  • 1
  • 8
  • 32
  • It allows doc files as well. Any solution, So it selects only PDF not any other type. – Tina Apr 17 '19 at 11:16
  • 1
    @Tina import CoreServices Then Enter types like this let _ = UIDocumentPickerViewController(documentTypes: [kUTTypePDF as String], in: .import) – Haider Awan Aug 26 '22 at 22:04
0

You can use Core Services for this work

import CoreServices

Then Enter types like this

let importMenu = UIDocumentPickerViewController(documentTypes: [kUTTypePDF as String, kUTTypePNG as String, kUTTypeJPEG as String], in: .import)

Or without Core Services

let importMenu = UIDocumentPickerViewController(documentTypes: ["com.adobe.pdf", "public.png", "public.jpeg"], in: .import)

Haider Awan
  • 81
  • 1
  • 2