open App DocumentDirectory with UIDocumentBrowserViewController

294 views Asked by At

hi i am developing a documentBrowser ViewController in my app so that user can browse files and folders inside documentDirectoy i was wondering is there any way to implement UIDocumentBrowser to open apps documentDirectory?

1

There are 1 answers

0
Kudos On

First,Call this function when you want to open DocPicker.

 func openDoc() {
            let documentPicker = UIDocumentPickerViewController(documentTypes:
                ["public.text",
                 kUTTypePDF as String,
                 "public.composite-content",
                 ], in: .open)
            documentPicker.delegate = self
        }

Secondly, Add Delegate in your class.

       extension DemoViewController: UIDocumentPickerDelegate {
        func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
            if var url = urls.first {
          //Do something with url.
            print(url)
           }
        }
    }