UIImagePickerController无法在Swift

时间:2018-05-01 15:41:08

标签: ios swift uiimagepickercontroller

当我通过UIImagePickerController选择图像时,我在xCode中得到以下输出:

  发现扩展时遇到

[discovery]错误:Error Domain = PlugInKit Code = 13“query canceled”UserInfo = {NSLocalizedDescription = query canceled}

这是我的代码:

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

}

我使用按钮打开ImagePicker:

@IBAction func chooseImageBtn(_ sender: Any) {
    imagePickerController.sourceType = .photoLibrary
    self.present(imagePickerController, animated: true, completion: nil)

}

当我在模拟器中启动应用程序时,我可以单击按钮,然后选择一个图像,然后选择器关闭,此消息显示在Xcode中:

  

2018-05-01 16:50:01.214450 + 0200真棒名称[57575:12752181] [MC]从私人有效用户设置中读取。

     

2018-05-01 16:50:03.740711 + 0200真棒名称[57575:12752241] [发现]发现扩展时遇到的错误:错误域= PlugInKit代码= 13“查询已取消”UserInfo = {NSLocalizedDescription =查询已取消}

我已经做了一些研究,但没有任何效果。 ImagePicker的委托设置为self,我也尝试在@objc之前添加func imagePickerController(_ picker:,但这并没有解决问题。

我还可以尝试显示所选图像?

1 个答案:

答案 0 :(得分:1)

尝试删除performeSegue功能,如果您确实需要使用它,只需将其添加到completion功能的dismiss即可。