Get the name of the chosen image from library using the following code in using Image Picker ViewController
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)img
editingInfo:(NSDictionary *)editingInfo{
[picker dismissModalViewControllerAnimated:YES];
NSURL *imagePath = [editingInfo objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString *imageName = [imagePath lastPathComponent];
NSLog(@"image name %@",imageName);
}
Here imageName variable will contains the name of the file chosen.
Thanks Vipin,
This solution helps me in swift. I have used the same concept in swift to get the filename.
In Swift it works like:-
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let gotImage = info[UIImagePickerControllerOriginalImage] as! UIImage
let imagePath: NSURL = (info[UIImagePickerControllerReferenceURL] as! NSURL)
let imageName: String = imagePath.lastPathComponent!
print(imageName)
self.dismissViewControllerAnimated(true, completion: nil)
}
if image is captured from camera so how can I get any name.