UIDocumentMenuViewController dismisses presenting view controller

1.9k Views Asked by At

I have a VC "A" that present VC "B" modally. B presents a UIDocumentMenuViewController The UIDocumentMenuDelegate protocol is implemented in B.

As soon as documentMenuWasCancelled(_ documentMenu:) or documentMenu(_:didPickDocumentPicker:) gets called the dismiss(animated:completion:) of B gets called and i have no clue why.

Here's my code

func presentDocumentPicker() {
    let documentTypes = [
        kUTTypeCompositeContent as String,
        kUTTypePDF as String,
        "com.microsoft.word.doc",
        "vnd.openxmlformats-officedocument.wordprocessingml.document"
    ]
    let documentMenuViewController = UIDocumentMenuViewController(documentTypes: documentTypes, in: .import)
    documentMenuViewController.delegate = self
    present(documentMenuViewController, animated: true, completion: nil)
}

// MARK: - Document Menu View Controller Delegate

func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
    print("did pick")
}

func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
    print("was cancelled")
}

As you can see I do nothing in the implemented delegate function. And still B gets dismissed. I don't get it.

1

There are 1 best solutions below

0
On

This is caused by documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) method which is called when you click on an action or when you cancel UIDocumentMenuViewController.

I posted a solution here: https://stackoverflow.com/a/45505488/6381503

Hope it helps.