-2

Like in templeRun, we also wish to add inAp purchase to give image.

http://www.youtube.com/watch?v=dYog6yhs0y4

How can I download image placed inside game bundle to iphone's photo library?

esqew
  • 42,425
  • 27
  • 92
  • 132
iPhone_360
  • 73
  • 5
  • I've added the answer below, but in the future it is advised that you research your question first before asking. There are a ton of examples of how to save a image to the photo library. I believe it is against the rules to ask duplicate questions without first doing research. – Allen S Jun 26 '14 at 15:25
  • 2
    possible duplicate of [How can I save an image to the camera roll?](http://stackoverflow.com/questions/11131050/how-can-i-save-an-image-to-the-camera-roll) – esqew Jun 26 '14 at 15:28

2 Answers2

1

Create a UIImage object from the picture within your bundle using imageNamed: and then use UIImageWriteToSavedPhotosAlbum() to save it to the Photo Library.

UIImage *image = [UIImage imageNamed:@"wallpaper.jpg"];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

For more information on the options for UIImageWriteToSavedPhotosAlbum() (callback functions, etc.) you can take a look at the UIKit Function Reference.

esqew
  • 42,425
  • 27
  • 92
  • 132
1

Call UIImageWriteToSavedPhotosAlbum , which I believe looks like this:

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

One way to use it is like this:

UIImage* myImage = [UIImage imageNamed:@"image.png"];

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

You only need to set the completion target and completion selector if you want to be notified if it succeeded or failed. If so, don't forget to add this method to the class:

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void*)contextInfo
{
    if (error)
    {
        // Do something on error... (like show a UIAlert for example)
    }
    else
    {
        // Do something on success... (maybe show a "Your image was saved" alert
    }
}

The image doesn't save right away and might error in the process so this can be useful.

You can also use the ALAssetsLibrary, which I believe would look like this:

ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

[library writeImageToSavedPhotosAlbum:[myImage CGImage] orientation:(ALAssetOrientation)[myImage imageOrientation] completionBlock:^(NSURL* assetURL, NSError* error)
{
    if (error)
    {
        // Do something on error... (like show a UIAlert for example)
    }
    else
    {
        // Do something on success... (maybe show a "Your image was saved" alert
    }
}];

Hope this helped.

Allen S
  • 1,042
  • 2
  • 9
  • 14