1

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?

Sergio
  • 1,610
  • 14
  • 28
  • 1
    Since you are passing the `import` mode (note that the initializer you are using is deprecated) you should not be going through initForExportingURLs, which is used to save a file to eg iCloud Drive. This must be a different document picker view controller elsewhere in your app. – Thomas Deniau Oct 14 '22 at 08:25
  • Strangely, this is the only occurrence of `UIDocumentPickerViewController` across the project. Could it be initialized indirectly from other places? – Sergio Oct 17 '22 at 09:04
  • Do you think `QLPreviewController` can somehow initialize a `UIDocumentUIPickerViewController`? – Sergio Oct 17 '22 at 10:25
  • 1
    Yes, if you tap "share" and then use "save to files". Have you filed a radar? – Thomas Deniau Oct 18 '22 at 10:57
  • https://stackoverflow.com/questions/74376975/why-all-these-sharesheet-errors – Sergio Nov 09 '22 at 15:00

1 Answers1

0

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

Sergio
  • 1,610
  • 14
  • 28