0

I am seeing the following error while trying to use UIDocumentPickerViewController in the simulator:

Error: the requested app extension could not be found

This in a production app that used to work fine. It reproduces in a minimal xcode project with one button that launches UIDocumentPickerViewController. I've tried following every tutorial I can find and downloading sample projects, and each one of them results in the same error. I'm using Xcode 12.3 and targeting iOS 14.

Is UIDocumentPickerViewController somehow completely broken and on one noticed, or (more likely) is there a step I'm missing?

Here are the steps I've taken to reproduce this

  1. Create a project in xcode 12.3 that uses Storyboards, UIKit Delegate app lifecycle and swift
  2. under Signing and Capabilities, add iCloud and Keychain Sharing (e.g. as described here)
  3. Added a button and the following implementation for ViewController.swift:
import UIKit
import MobileCoreServices
import UniformTypeIdentifiers

class ViewController: UIViewController, UIDocumentPickerDelegate, UINavigationControllerDelegate  {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        print("import result : \(urls)")
    }

    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
       dismiss(animated: true, completion: nil)
    }

    @IBAction func browse(_ sender: Any) {
        let supportedTypes: [UTType] = [UTType.image]
        let importMenu = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes, asCopy: true)
        importMenu.delegate = self
        importMenu.modalPresentationStyle = .formSheet
        self.present(importMenu, animated: true, completion: nil)
    }

}

Run the app and click the button. The above error is displayed.

The only reference I've found to this error is here: iOS 13: MPMediaPickerController - Internal Error / The requested app extension could not be found

Does the UIDocumentPickerViewController require permissions? I haven't found any indication online.

I've tried variously setting the deployment target to iOS 12 and 13, with no luck. I've also tried initializing the document picker using the deprecated init(documentTypes:..) and the non-deprecated init(forOpeningContentTypes:...), as well as setting containers in the icloud/keychain settings.

I would greatly appreciate any help on this problem.

Thank you!

Amos Joshua
  • 1,601
  • 18
  • 25
  • Does it work on a device? – matt May 31 '21 at 10:05
  • I am not able to test on a device at the moment, so I don't know – Amos Joshua May 31 '21 at 10:17
  • Try this `let importMenu = UIDocumentPickerViewController(documentTypes: ["public.text", kUTTypePDF as String, "demo"], in: .open)` And dont forget to add `if #available(iOS 13.0, *) { documentPicker.shouldShowFileExtensions = true }` – Kudos May 31 '21 at 12:09
  • @Kudos thanks for the suggestion - unfortunately I still get the same error. – Amos Joshua May 31 '21 at 12:49
  • Have you tried to "Erase all content and settings…". Maybe it's something like the last path used in the document picker, that doesn't work any longer. – D. Mika Jun 01 '21 at 10:39
  • @matt I have finally gotten access to a device and it does in fact work for devices. If you'd like to post your comment as an answer I will accept it. – Amos Joshua Jun 04 '21 at 15:00

0 Answers0