0

I have a problem with PHAsset.In my app a get image from gallery through the method :

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

I take the photo and it works fine. Now i need the name of photo and in case it doesn't exist, because it's a new photo from camera, i must save it.

I'm not able to get the filename of selected image, my code returns or the first name of assets or the last. I used this code;

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];

    NSData *imgComprData = UIImagePNGRepresentation(chosenImage) ;

    ......

    PHAsset *asset = nil;
    PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];

    PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
    if (fetchResult != nil && fetchResult.count > 0) {

        asset = [fetchResult firstObject]; //first object is wrong
      }


    NSArray *resources = [PHAssetResource assetResourcesForAsset:asset];
    NSString *orgFilename =   ((PHAssetResource*)resources[0]).originalFilename;
    ....
}

How can i obtain the name of the the selected image from gallery?? If it doesn't exist, can i save it and then get the filename??

I can't use ALAsset because it's deprecated.

Thank you for your help.

pampua84
  • 438
  • 4
  • 18
  • Sorry but in the link that you have posted, the user takes last or first name of assets, and i don't want it, but i need the name of selected image, not of general assets. – pampua84 May 04 '16 at 15:59
  • look to this link, you will have a lot of imagePickerController:- [link](http://stackoverflow.com/questions/20756899/how-to-select-multiple-images-from-uiimagepickercontroller) – Ahmed Abdallah May 04 '16 at 16:16
  • Maybe, i'm not clear, i'm able to get all assets but i don't able to get filename of image that i have selected in photo galerry (i want the filename of one selected photo) – pampua84 May 05 '16 at 06:39
  • I solved my problem, i used PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:arrayOfUrl options:nil] and the rest of code that i had posted. Thank you – pampua84 May 05 '16 at 08:30

0 Answers0