I am trying to get the image path from camera using UIImagePickerController
here is the code :
@IBAction func takePhoto(sender: UIButton) {
imagePicker = UIImagePickerController()
imagePicker?.allowsEditing = true
imagePicker?.delegate = self
imagePicker?.sourceType = .Camera
presentViewController(imagePicker!, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let imageURL = info[UIImagePickerControllerReferenceURL] as? NSURL
print(" Path \(imageURL)")
imageView?.contentMode = .ScaleAspectFit
imageView?.image = info[UIImagePickerControllerOriginalImage] as? UIImage
imagePicker?.dismissViewControllerAnimated(true, completion: nil)
}
any help ?
Delegate didFinishPickingMediaWithInfo
gets called after a pic is taken using the camera. UIImagePickerControllerReferenceURL
object will be nil
as the image has not been saved to the camera roll yet.
To get rid of this situation, you need to first save the image and then use the url of the path you saved. You can however use UIImagePickerControllerOriginalImage
property on info
to show the taken image in your application. Hope this helps!