我有一个文档选择器,但在选择文档后,永远不会触发 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)
}
也没有什么是“失败”的,它只是没有调用 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)")
}
编辑:
我刚刚添加了 documentPickerWasCancelled
方法,出于某种原因,当我选择文档时会调用该方法。
请注意,我正在从谷歌驱动器中选择一个文档,这会对任何事情产生影响吗?
编辑 2: 回答,卸载并重新安装,它工作。请参阅下面的答案。谢谢大家的建议。
最佳答案
上面的代码看起来是正确的。我卸载了谷歌驱动器应用程序(我从中获取文件)并重新安装它,然后它按预期工作。我也从 Dropbox 尝试过,效果也很好。
之前不确定是什么导致它失败。
关于ios - UIDocumentPickerViewController 不调用 didPickDocument 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40156074/