我有一个文档选择器,但是在选择一个文档后,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:回答,卸载并重新安装并且它有效。请参阅下面的答案。谢谢大家的建议。