views:

31

answers:

1

I want to get a file from the Camera or the Photo Library and I know how to get the file using the UIImagePickerController.

The thing I don't know is how to keep reference to that file in my source ( for example, I want to save some record, and my record has reference to the image in Photo Library).

Example

  1. User captures photo with camera
  2. I take the photo and save it into Photo Library
  3. I keep the reference to the file in Photo Library and when needed I show the file to the user (without showing the UIImagePickerController, just grabbing the file from the library and showing it to the user)

how to keep the reference? Is it path? is it some Photo Library ID?

Any help appreciated.

+1  A: 

There is no way to save a reference to an image in the library. What you've got 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");
}
kubi