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.