Search code examples
iosswiftobjective-ccrashlyticsuidocumentpickerviewcontroller

How to reproduce UIDocumentUIPickerViewController NSCocoaErrorDomain Code=260?


I am presenting the UIDocumentUIPickerViewController from a view controller like this:

let documentPicker = UIDocumentPickerViewController(
  documentTypes: [String(kUTTypePDF), String(kUTTypeImage)], 
  in: .import
)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .fullScreen
present(documentPicker, animated: true, completion: nil)

Everything seems to work nicely. I select a file and get its URL in documentPicker(controller:url:)

But I am getting several crashes in Firebase like this:

-[UIDocumentPickerViewController initForExportingURLs:asCopy:] must be called with a URL pointing to an existing file: Error Domain=NSCocoaErrorDomain Code=260 UserInfo (NSURL=file:///var/mobile/Containers/Data/Application/APP_ID/Documents/FILE.pdf, NSFilePath=/var/mobile/Containers/Data/Application/APP/ Documents/FILE.pdf, (Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"))

Only >= iOS 16 users are affected, but I didn't manage to reproduce the error, and from what I've read, it seems to be an Apple issue.

It'd be nice to generate the error myself so that I can upload a fixed version to the App Store. But until I don't manage to reproduce the error, I can't prove that any solution is working.

I've tried to select big files with a feeble connection, but with no success...

Any ideas?


Solution

  • As Thomas Deniau suggested in the comments, we managed to reproduce the bug by saving it to files. Check this answer.