Parham Hasaninia
Parham Hasaninia

Reputation: 23

How to use UIImagePickerController in swift 4

I am trying to get image from camera or photo library and use an UIImageView to preview that photo. I use the code below to capture image :

let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = .camera
present(picker, animated: true, completion: nil)

and then I use this code to put image in imageView :

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}

I get permission and the app load successfully on my IPhone but when I capture a picture it doesn't go back to main View to show on image view . and it crash . can any body help me ?

Upvotes: 1

Views: 3314

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100541

You need to dismiss end of the function didFinishPickingMediaWithInfo

picker.dismiss(animated:true,completion:nil)

Upvotes: 1

Related Questions