According to this:
https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories
iOS 13 adds the ability of UIDocumentPickerViewController to select a directory, including directories from 3rd party file providers.
On click of button in the ViewController, calling below function "showPickerView"
We are using below code snippet, to access external USB drive via lightening cable
func showPickerView() {
let url = URL(string: "/some_path_here/NO%20NAME/DCIM")!
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String], in: .open)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
documentPicker.directoryURL = url
documentPicker.modalPresentationStyle = .custom
documentPicker.definesPresentationContext = true
documentPicker.transitioningDelegate = customTransitioningDelegate
self.present(documentPicker, animated: true, completion: nil)
}
Once this function is called below popup is displayed,
User will click the the "Done" label which will invoke the below code.
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let url = urls.first else {
return
}
print(url)
//Access using security-scoped resource
}
Our goal: Instead of showing popup of document picker and clicking on "Done" button, directly access file from External drive (External drive's path we already know)
Reason: For end user, this pop up is annoying.
Options we have tried
- Show the Document Picker but automatically close it.
Get the object of "Done" button on top right side - execute the
buttonObj.sendActions(for: .touchUpInside)
- Programmatically, provide some gesture/shortcut which will played once this popup is opened
- Hide this pop up by changing the opacity or visibility option.
Currently any of the above option is not working.
Please tell us, if any other recommended way to solve this problem.
Thank you !