Get file path of saved image to camera roll iOS (Obj-c)

1.2k views Asked by At

I used UIImageWriteToSavedPhotosAlbum to save image to Camera Roll, but I want to get a reference to get back to the same image. Is it possible? I have a link (albeit in Japanese) that says it's possible to get the file path, but as of what I understand this is during selection (using imagePicker) and not before/after taking a picture. What I want is to get the reference of the image, save it in CoreData, and the use it later to fetch the image.

Edit: It seems as if there is an answer already but in the comments it says that ALAssetsLibrary is already deprecated and we should use PHPhotoLibrary instead.

2

There are 2 answers

0
Harsh Srivastava On

just pass the file name and extension to fetch the image

+(UIImage *)loadImage:(NSString *)fileName ofType:(NSString *)extension {
NSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
UIImage * result = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", documentsDirectoryPath, fileName, extension]];
return result; }
0
Badal Shah On

You Can Get All the Photos, Videos and Other Data With Using PHAsset Library. Here is Code to get All Videos in Array .

//For Video

allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:nil];

For Image you Can use this

//For Images

allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];

and You can Display it Using PHAsset in UiTableview or Any Other Control.

Here is the URL of Demo ,

AVPlayer Demo (Fetch Video With PHAsset Library)