I m trying to implement UIImagePicker
in my application. Now i m retrieving the image from the photo library. Is there any way in which i can retrieve the name of the image from photo library ?
tried UIImagePicker
methods but cant find one. Any one.. ?
Thanks..
Asked
Active
Viewed 3,740 times
1

Joshua Nozzi
- 60,946
- 14
- 140
- 135

Hadi
- 1,212
- 2
- 17
- 31
-
1no there is no way to get the image name.You can only get the image. – Gypsa Jul 18 '11 at 04:56
3 Answers
2
image picker delegate method returns you the dictionary from which you can get image path by using "UIImagePickerControllerReferenceURL" as key and finally extract last path component of path to get image name
NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSString *imageName = [imagePath lastPathComponent];
1
If you want a result like this: [filename ] IMG_0012.JPG, pls see my answer here: how to pick the image name and image from iPhone photo library in iOS
Here is the code (don't forget to import Photos/Photos.h):
NSURL *imagePath = [editingInfo objectForKey:UIImagePickerControllerReferenceURL];
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[imagePath] options:nil];
NSString *filename = [[result firstObject] filename];
NSLog(@"[filename ] %@", filename );

Panayot
- 484
- 1
- 6
- 18
-
Panayot, instead of posting an answer which merely links to another answer, please instead [flag the question](https://stackoverflow.com/help/privileges/flag-posts) as a duplicate. – 4b0 Aug 10 '18 at 08:54
-
Thanks for the info! I will edit my answer ASAP. Sorry, I'm new here and I think that if I post again my answer here, this will be marked as duplicate answer or something like this... – Panayot Aug 10 '18 at 09:54
-
Answers don't get marked as duplicates, only questions. If the two questions are indeed duplicates, one should be closed, in which case there will be a link to the other question with your answer. – CJ Dennis Aug 10 '18 at 12:41
-
Please provide more context around the code – code comments and a description of what the code is doing exactly are valuable for future users with similar questions. – Greenstick Aug 10 '18 at 17:22
-
It's clear - this is an answer of the question: " Is there any way in which i can retrieve the name of the image from photo library ? " - Yes, it is possible, and this is the way.. – Panayot Aug 10 '18 at 20:18
1
In the delegate method of UIImagePickerController called
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
you can use the info dictionary to get the reference url of the image that the user picked by using key UIImagePickerControllerReferenceURL
and get the file name from it.

Robin
- 10,011
- 5
- 49
- 75