I'm trying to use UIDocumentPickerViewController from SwiftUI using UIViewControllerRepresentable. I've managed to show a file picker dialog, but it doesn't allow multiple file selection even when I set allowsMultipleSelection to true.
Is this a bug or am I doing something wrong?
Here's the code:
import SwiftUI
import UIKit
import CoreServices
struct DocumentPicker: UIViewControllerRepresentable {
typealias UIViewControllerType = UIDocumentPickerViewController
func makeUIViewController(context: Context) -> UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(documentTypes: [kUTTypeImage as String], in: .open)
picker.allowsMultipleSelection = true
return picker
}
func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) { }
}
And here's the test view which triggers the picker.
import SwiftUI
struct ContentView: View {
@State var isPickerPresented = false
var body: some View {
Button("Show Picker") {
isPickerPresented = true
}.sheet(isPresented: $isPickerPresented) {
DocumentPicker()
}
}
}