0

I am capturing image with camera. After capturing i want to get the url so that i can get the image name.I am using below code for this.

 PHObjectPlaceholder *assetholder;
        PHPhotoLibrary *objPhoto = [PHPhotoLibrary sharedPhotoLibrary];
        [objPhoto performChanges:^{

        PHAssetChangeRequest *assets = [PHAssetChangeRequest creationRequestForAssetFromImage:info[UIImagePickerControllerOriginalImage]];
        PHObjectPlaceholder *assetholder = assets.placeholderForCreatedAsset;

        } completionHandler:^(BOOL success, NSError * _Nullable error) {


        }];

Suggest me how can i get url of the image so that i can get image name.

iOSGuy
  • 171
  • 1
  • 14
  • guys similar - LARGE BOUNTY - http://stackoverflow.com/questions/43791151/100-bounty-actually-get-the-filename-of-image-saved-to-photos-album-2017-ios10 – Fattie May 10 '17 at 11:08

1 Answers1

1
PHAsset *asset = nil;
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
if (fetchResult != nil && fetchResult.count > 0) {
    // get last photo from Photos
    asset = [fetchResult lastObject];
}

if (asset) {
    // get photo info from this asset
    PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc] init];
    imageRequestOptions.synchronous = YES;
    [[PHImageManager defaultManager]
             requestImageDataForAsset:asset
                            options:imageRequestOptions
                      resultHandler:^(NSData *imageData, NSString *dataUTI,
                                      UIImageOrientation orientation, 
                                      NSDictionary *info) 
     {
          NSLog(@"info = %@", info);
          if ([info objectForKey:@"PHImageFileURLKey"]) {
               // path looks like this - 
               // file:///var/mobile/Media/DCIM/###APPLE/IMG_####.JPG
               NSURL *path = [info objectForKey:@"PHImageFileURLKey"];
     }                                            
    }];
}
Parth Adroja
  • 13,198
  • 5
  • 37
  • 71