Error with ImagePicker in swift 3

0

I'm trying to get an image of the camera or the library. I can take the image, the problem is that it does not save it.

I have set print test but I also do not get the delegated function to save the image.

var imagePicker = UIImagePickerController()

override func viewDidLoad() {
    super.viewDidLoad()

    imageView.isUserInteractionEnabled = true
}

//A esta funcion no llega porque no me muestra el print
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    let image = info[UIImagePickerControllerOriginalImage] as? UIImage
    self.imageView.image = image

    print("TEST")

    self.imagePicker.dismiss(animated: true, completion: nil)
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    self.dismiss(animated: true, completion: nil)
}

@IBAction func cogerImagen(_ sender: UIButton) {
    self.imagePicker = UIImagePickerController()
    self.imagePicker.delegate = self
    self.imagePicker.sourceType = .photoLibrary
    self.imagePicker.isEditing = true
    self.present(self.imagePicker, animated: true, completion: nil)
}
    
asked by 04.10.2016 в 13:30
source

2 answers

0

Remember that you must set the delegate in one of these two ways:

Option 1:

var imagePicker = UIImagePickerController() {
    didSet {
        imagePicker.delegate = self
    }
}

Option 2:

override func viewDidLoad() {
    super.viewDidLoad()

    imagePicker.delegate = self
    imageView.isUserInteractionEnabled = true

}
    
answered by 04.10.2016 / 14:21
source
0

One of the problems I have corrected with the @mhergon solution

But another problem was that the parameters of the function have changed. The solution is:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    
answered by 04.10.2016 в 14:39