Reputation: 617
Kindly let me know the way to get the path of the image selected using the picker view.
func addImage(sender: AnyObject){
picController.allowsEditing = false
picController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(picController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
self.dismissViewControllerAnimated(true, completion: nil)
titleImageView.image = image
//Get the path of the image selected
// print(path)
}
I would like to print the path of the image. Thank you
Upvotes: 2
Views: 6114
Reputation: 617
Working code
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
self.titleImageView.image = image
let url: NSURL = editingInfo.valueForKey("UIImagePickerControllerReferenceURL") as! NSURL
print(url.absoluteString)
self.dismissViewControllerAnimated(true, completion: nil)
}
Upvotes: 2
Reputation: 14304
The UIImagePickerController
API you're using provides a reference to a UIImage object via delegation. With this UIImage reference you can write the image to file and use that path. In order to obtain a reference to the image asset in the library, you'll need to use a different delegate callback: didFinishPickingMediaWithInfo
. Simply obtain the path from the info dictionary's UIImagePickerControllerReferenceURL
.
For more information, see Apple's documentation.
Upvotes: 0