Fabian
Fabian

Reputation: 571

UIImagePickerController not working in Swift

When I choose an image via the UIImagePickerController, I get the following output in xCode:

[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

This is my code:

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)
}

The ViewController class is declared as it should be:

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

}

I use a button to open the ImagePicker:

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

When I start the App in the simulator, I can click on the button, and choose an image but then the picker gets closed and this message is shown in Xcode:

2018-05-01 16:50:01.214450+0200 Awesome Name[57575:12752181] [MC] Reading from private effective user settings.

2018-05-01 16:50:03.740711+0200 Awesome Name[57575:12752241] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

I already did some research but nothing worked. The delegate of the ImagePicker is set to self, and I also tried adding @objc before func imagePickerController(_ picker: but that did not solve the problem.

What else can I try to display the selected image?

Upvotes: 0

Views: 1452

Answers (1)

Houcem Eddine Soued
Houcem Eddine Soued

Reputation: 236

Try removing the performeSegue function, if you really need to use it just add it on the completion of the dismiss function .

Upvotes: 1

Related Questions