42 lines
1.3 KiB
Swift
42 lines
1.3 KiB
Swift
import SwiftUI
|
|
import UIKit
|
|
|
|
struct AttachmentFilesPickerView: View {
|
|
var body: some View {
|
|
DocumentPicker()
|
|
}
|
|
}
|
|
|
|
struct DocumentPicker: UIViewControllerRepresentable {
|
|
func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) -> UIDocumentPickerViewController {
|
|
let picker: UIDocumentPickerViewController
|
|
picker = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true)
|
|
picker.delegate = context.coordinator
|
|
picker.allowsMultipleSelection = true
|
|
return picker
|
|
}
|
|
|
|
func updateUIViewController(_: UIDocumentPickerViewController, context _: UIViewControllerRepresentableContext<DocumentPicker>) {}
|
|
|
|
func makeCoordinator() -> Coordinator {
|
|
Coordinator(self)
|
|
}
|
|
|
|
class Coordinator: NSObject, UIDocumentPickerDelegate {
|
|
var parent: DocumentPicker
|
|
|
|
init(_ parent: DocumentPicker) {
|
|
self.parent = parent
|
|
}
|
|
|
|
func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) {
|
|
// TODO: Send documents
|
|
// Handle the selected files
|
|
}
|
|
|
|
func documentPickerWasCancelled(_: UIDocumentPickerViewController) {
|
|
// Handle cancellation
|
|
}
|
|
}
|
|
}
|