views:

405

answers:

3

How can I save and open photos from the iPhone's photo library from my app? Code would be helpful.

A: 

Picking Images with the iPhone SDK UIImagePickerController

Tobias Cohen
I am trying to open and save without the interface.I open an image using this method then I need to reopen it the next time my app launches.
cduck
This is a restriction of the iPhone platform. They don't really want you writing apps that silently load photos in the background. Might be worth filing a feature request on Radar, though (See Kendall's answer)
Ben Gotow
@cduck To enable persistence, just save a copy of the image in your App's Documents folder. For obvious reasons, you can't just grab images from the Photo Library without the User's permission.
Tobias Cohen
+1  A: 

This allows you to save an image to the photo album:

// Adds a photo to the saved photos album.  The optional completionSelector should have the form:
//  - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;
UIKIT_EXTERN void UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);

(sample code: )

IImageWriteToSavedPhotosAlbum( image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil );  


/// called function, alerts user when the image has been saved:

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    [ [ self parentViewController ] dismissModalViewControllerAnimated: YES];   
}
justin
How can the image be reopened without the user having to pick the image from a UIImagePickerController the next time I launch my app?
cduck
Unfortunately, after doing some digging, it may be that part is not possible for applications released via the AppStore. You can save them to both the Album and your own directory (and you can open the ones in your own directory with no problem), but it does not appear that applications have access to the camera's photo album.
justin
A: 

The best you can do is saved off a picked photo in your own app writable directory, and use that going forward... note that if you save out to the users library multiple times, it will create a new image every time.

You may want to file a Radar with Apple to allow direct access to the file, or give you some kind of reference you could use to see the file (to see EXIF for example).

Kendall Helmstetter Gelner
I'll do that.__
cduck