UIDocumentPickerViewController: Cannot access file from OneDrive

Hello everybody,

I am struggling with accessing files from the Location OneDrive through UIDocumentViewController.

The error says:

Error Domain=NSCocoaErrorDomain Code=260 "Die Datei „Testfile.txt“ konnte nicht geöffnet werden, da sie nicht existiert." UserInfo={NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/11E04153-649E-416F-9860-2EA9C0913A18/File Provider Storage/item|1|18a17c69%2D5d6d%2D4b16%2Db388%2D4a9834e9440b/Testfile.txt, NSUnderlyingError=0x281202310 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

The Controller is initialised the following way:

let ctrl = UIDocumentPickerViewController(forOpeningContentTypes: [.image, .audio, .video, .item, .content])

And in the delegate method I do the following:

        func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
            
            guard let documentUrl = urls.first else { return }
            guard documentUrl.startAccessingSecurityScopedResource() else {
                parent.errorText = "Developer Error: Can't access security scoped resource."
                return
            }
            defer {
                documentUrl.stopAccessingSecurityScopedResource()
            }
            do {
                let data = try Data(contentsOf: documentUrl)
            } catch {
                parent.errorText = error.localizedDescription
            }
        }

Any help is appreciated!

Thanks

I am using iOS 17.3.1

Does your code work if you target a different file provider, such as iCloud Drive?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

After trying a little bit around, I think it is because OneDrive does not have its file locally, hence the error "no such file or directory". If in OneDrive I mark the file as "keep offline available", then it works.

So the question would now rather be: How can I detect such a linked file, and is there a possiblity to download the file located in OneDrive first from UIDocumentPickerViewController?

One thing that springs to mind here is TN3150 Getting ready for dataless files. However, It doesn’t really explain the behaviour you’re seeing. My expectation is that the URL being returned by your file provider should be valid. If it isn’t, that seems to be an issue with the file provider.

I did not test it with Dropbox though.

You wanna try that? iCloud Drive is built in to the system and hence a bit weird, so it’d be useful to know if this works as I expect in other third-party file providers.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

UIDocumentPickerViewController: Cannot access file from OneDrive
 
 
Q