UIDocumentPickerViewController 不调用 didPickDocument 方法

Joh*_*ohn 5 ios swift uidocumentpickervc

我有一个文档选择器,但选择文档后,didPickDocumentAt 部分永远不会被触发。在我更新 swift 之前它可以工作,现在有什么不同吗?

func selectDocument(_ sender: UIButton!){
    let documentPickerVC = UIDocumentPickerViewController(documentTypes: ["org.openxmlformats.wordprocessingml.document", "com.microsoft.word.doc"], in: UIDocumentPickerMode.import)
    documentPickerVC.delegate = self
    self.present(documentPickerVC, animated: true, completion: nil)
}

func documentPicker(_ documentPicker: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    print("file picked: \(url)")
    documentPicker.dismiss(animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

也没有什么“失败”,它只是没有调用该documentPicker方法。

我有一个类似的用于选择媒体的工具,并且效果很好......

func selectMedia(_ sender: UIButton!){
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary){
        picker.delegate = self
        picker.allowsEditing = false
        picker.mediaTypes = [kUTTypeMovie as String]
        self.present(picker, animated: true, completion: nil)
    }
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:[String: Any]) {
    let url = info[UIImagePickerControllerMediaURL] as! URL
    print("media picked: \(url)")
}
Run Code Online (Sandbox Code Playgroud)

编辑:我刚刚添加了该documentPickerWasCancelled方法,并且由于某种原因,当我选择文档时会调用该方法。注意我正在从谷歌驱动器中选择一个文档,这会对任何事情产生影响吗?

编辑2:已回答,卸载并重新安装,它起作用了。请参阅下面的答案。谢谢大家的建议。

Joh*_*ohn 1

上面的代码看起来是正确的。我卸载了谷歌驱动器应用程序(我从中获取文件的地方)并重新安装它,然后它按预期工作。我也从 dropbox 尝试过,效果也很好。

不确定之前是什么原因导致它失败。