Search code examples
iosswiftmultipleselectionuidocumentpickerviewcontroller

Multiple selection for document picker controller


I am trying to select multiple files in document picker. Here is my code:

let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeFolder)], in: .import)
documentPicker.delegate = self
self.present(documentPicker, animated: false) {
    if #available(iOS 11.0, *) {
        documentPicker.allowsMultipleSelection = true
    }
}

But it is selecting only 1 file at a time. Can anyone suggest me a correct way?

Any help would be highly appreciated!!


Solution

  • Just do it before

    self.present

    your code should be

     let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypeFolder)], in: .import)
            documentPicker.delegate = self
            if #available(iOS 11.0, *) {
                 documentPicker.allowsMultipleSelection = true
             }
            self.present(documentPicker, animated: false) {
    
            }
    

    and check in Browse tab, not in Recenets tab