Reputation: 724
I've looked at a lot of solutions which, sadly, did not work for me. I used this code to create an imagePickerController:
@IBAction func takePhoto(sender: UIButton) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.allowsEditing = false
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, _didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
imageView.contentMode = .ScaleAspectFit
imageView.image = pickedImage
dismissViewControllerAnimated(true, completion: nil)
}
But still the image I take on the camera doesn't show up in the imageView. I also imported the correct delegates. When I try to print the imageView.image to the console it returns nil
. What am I doing wrong?
Upvotes: 0
Views: 350
Reputation: 757
Please try this code. Hope it will help you.
func cameraPhoto(){
imagePicker.allowsEditing = true
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.cameraCaptureMode = .Photo
imagePicker.cameraDevice = .Front;
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage
}
Thanks
Upvotes: 1