当我通过UIImagePickerController选择图像时,在xCode中得到以下输出:
[发现]发现扩展时遇到错误:Error Domain=PlugInKit Code=13“query cancelled”UserInfo={NSLocalizedDescription=query cancelled}
这是我的代码:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
imagePicked = image
dismiss(animated: true, completion: nil)
performSegue(withIdentifier: "showImage", sender: self)
}
ViewController类声明如下:
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
let imagePickerController = UIImagePickerController()
var imagePicked = UIImage()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
imagePickerController.delegate = self
}
我用一个按钮打开图像选择器:
@IBAction func chooseImageBtn(_ sender: Any) {
imagePickerController.sourceType = .photoLibrary
self.present(imagePickerController, animated: true, completion: nil)
}
当我在模拟器中启动应用程序时,我可以单击按钮,然后选择一个图像,但是选择器会关闭,此消息显示在Xcode中:
2018-05-01 16:50:01.214450+0200 Awesome Name[57575:12752181][MC]从私人有效用户设置中读取。
2018-05-01 16:50:03.740711+0200 Awesome Name[57575:12752241][discovery]发现扩展时遇到错误:Error Domain=PlugInKit Code=13“query cancelled”UserInfo={NSLocalizedDescription=query cancelled}
我已经做了一些研究,但什么也没用。ImagePicker的委托设置为
self
,我还尝试在@objc
之前添加func imagePickerController(_ picker:
,但这并不能解决问题。我还可以尝试显示选定的图像吗?
最佳答案
尝试删除performeSegue
函数,如果您真的需要使用它,只需将它添加到completion
函数的dismiss
上。
关于ios - UIImagePickerController在Swift中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50119459/