Save image to iphone Camera roll from Url

Saving an image from Url to iphone Camera roll is easy. We can do it after few steps:

First step you need to get image from url

 

UIImage * image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"Your URL String"]]];

 

Now request to save the image to camera roll.

void UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);

Here is how to use it :

 

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

 

And specify the selector

I will create an alert that show “Saved to Camera Roll” when completed.

 

- (void)image:(UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {
 UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil  message:@"Saved to Camera Roll" delegate:nil cancelButtonTitle:@"OK"  otherButtonTitles:nil];
 [alert show];
 [alert release];
 if(error != nil) {
 // Write your code to handle error
 }
 [image autorelease];
 }

 

Simple!