I\'ve been working on a simple application which allows the user to take a photo and store it in the camera roll for later use. To do this, I am using a UIImagePickerControl
It turns out that it is actually not that hard to do this. In the UIImagePickerDelegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
the NSDictionary "info" actually contains the url to the image or the movie which is stored on the Camera Roll. You need only check:
if([[info valueForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]){ // If the user took a video,
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] retain];// Get the URL of where the movie is stored.
UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); // Save the movie to the photo album.
}
and this will save the movie to the Camera Roll, as well as record the url. Doing it for a photo is analogous, just replace the "kUTTypeMovie" with "kUTTypeImage", and replace
movieURL = [[info valueForKey:UIImagePickerControllerMediaURL] retain];// Get the URL of where the movie is stored.
UISaveVideoAtPathToSavedPhotosAlbum([movieURL path], nil, nil, nil); // Save the movie to the photo album.
with
UIImage * image = [info valueForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
If you need to store the UIImage not on the Camera Roll, there is a great post on stackoverflow Saving UIImage with NSCoding that you can use to store the image in your app. Hope that helps someone!