How to save a link to a file saved in Photo Library

I want to get a file from a camera or photo library, and I know how to get a file using UIImagePickerController.

I don’t know how to save the link to this file in my source (for example, I want to save some record, and my record has a link to the image in Photo Library).

Example

  • User captures photo using camera
  • I take a photo and save it in Photo Library.
  • I save the link to the file in Photo Library and, if necessary, I show the file to the user (without displaying the UIImagePickerController, I just grab the file from the library and show it to the user)

How to save the link? Is that the way? Is this some kind of photo library id?

Any help was appreciated.

+3
source share
1 answer

There is no way to save the link to the image in the library. What you need to do is save the image yourself and remember the location.

NSData *imageData = UIImagePNGRepresentation(image);
NSString *cachedImagePath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/cached.png"];
if (![imageData writeToFile:cachedImagePath atomically:NO]) {
    NSLog(@"Failed to cache image data to disk");
}
+3
source

Source: https://habr.com/ru/post/1764147/


All Articles