Image save on button click
<p>i want to save an image from camera or already saved image to photo library in iphone.
Here i implemented a code but i cant implement it on button click moreover its getting crash.
I am very new to iphone programming side. Please give some help.</p>

<pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info:(id)sender{
    UIImage *selectedImage;
    NSURL *mediaUrl;

    mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
    if (mediaUrl == nil)
    {
        selectedImage = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage];
        if (selectedImage == nil)
        {
            selectedImage = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
            NSLog(@"Original image picked.");
        }
        else
        {
            NSLog(@"Edited image picked.");
        }
    }
    else
    {
        NSLog(@"Video picked. Not yet implemented.");
    }

    [picker dismissModalViewControllerAnimated:YES];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    if((UIButton *) sender == savePhotoBtn) {
        UIImageWriteToSavedPhotosAlbum(selectedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    }
}
</code></pre>
