1

I am new in iOS and I am facing problem regarding to show file path on UILabel. I am taking Image for gallery and I want to show Image name and its extension on UILabel.

My code is like this

Button Click...

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker animated:YES completion:nil]; 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    imgPanCard.image = image;
    [picker dismissModalViewControllerAnimated:YES];
}

enter image description here

I need to show Image name and its extension on UILabel "No. File Chosen" How to do this.Thanks in Advance!

Muju
  • 884
  • 20
  • 54
  • 2
    Check this http://stackoverflow.com/questions/4314405/how-can-i-get-the-name-of-image-picked-through-photo-library-in-iphone – RajeshKumar R Mar 30 '17 at 11:12
  • 1
    Try this http://stackoverflow.com/a/20251513 – Rajesh Dharani Mar 30 '17 at 11:15
  • @RajeshkumarR I try your code but - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo method not get call after calling this method didFinishPickingMediaWithInfo – Muju Mar 30 '17 at 11:30
  • @RajeshkumarR Are you there??? – Muju Mar 30 '17 at 11:40

2 Answers2

0

I just change code like this

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
        NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];

        // define the block to call when we get the asset based on the url (below)
        ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
        {
            ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
            NSLog(@"[imageRep filename] : %@", [imageRep filename]);
            lblPanCard.text=[imageRep filename];
            [picker dismissViewControllerAnimated:NO completion:nil];
            imgPanCard.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        };

        // get the asset library and fetch the asset based on the ref url (pass in block above)
        ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
        [assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];

}
Muju
  • 884
  • 20
  • 54
-1

Add following code in "didFinishPickingMediaWithInfo" method:

// get the ref url
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];

// define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
    ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
    NSLog(@"[imageRep filename] : %@", [imageRep filename]);
};

// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
Hiren Patel
  • 190
  • 7
  • Don't copy paste answer to another question if answer is available than share link in comment box – Jigar Mar 30 '17 at 11:17
  • @HirenPatel Your code give me Image name and Extension but it not work after choose when selecting image from gallery. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo Method not getting call. – Muju Mar 30 '17 at 11:29