Hey,
I have been working with the UIDocumenPickerViewController in the last few days.
This is my current code:
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypePlainText as String], in: .open)
documentPicker.delegate = self
if #available(iOS 11.0, *)
{
documentPicker.allowsMultipleSelection = false
}
else { }
present(documentPicker, animated: true, completion: nil)
Now my question: After this code I call the didPickDocumentAt Methode
documentPicker(, didPickDocumentsAt: )
But I have no idea what I should put in it, I tried it like this
documentPicker(documentPicker, didPickDocumentsAt: [UIDocumentPickerMode.open])
I tried it like this but then I always get the Error: Cannot call value of non-function type 'UIDocumentPickerViewController'
And my second question is: I want to acces the content of the selected File and found this in the documentation https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories
If you go to Access the Directory´s content you find this code
// Start accessing a security-scoped resource.
guard url.startAccessingSecurityScopedResource() else {
// Handle the failure here.
return
}
// Make sure you release the security-scoped resource when you are done.
defer { url.stopAccessingSecurityScopedResource() }
// Use file coordination for reading and writing any of the URL’s content.
var error: NSError? = nil
NSFileCoordinator().coordinate(readingItemAt: url, error: &error) { (url) in
let keys : [URLResourceKey] = [.nameKey, .isDirectoryKey]
// Get an enumerator for the directory's content.
guard let fileList =
FileManager.default.enumerator(at: url, includingPropertiesForKeys: keys) else {
output.append("*** Unable to access the contents of \(url.path) ***\n")
return
}
for case let file as URL in fileList {
// Also start accessing the content's security-scoped URL.
guard url.startAccessingSecurityScopedResource() else {
// Handle the failure here.
continue
}
// Make sure you release the security-scoped resource when you are done.
defer { url.stopAccessingSecurityScopedResource() }
// Do something with the file here.
}
}
Where do they get the url from in the beginning? The documentation never explains where the url got created.
Thank you for your help
Regards,
Tell