IOS Get image name in Image Picker ViewConroller

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.

2 thoughts on “IOS Get image name in Image Picker ViewConroller”

  1. 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)
    }

    Reply

Leave a Comment