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?
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?
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
.
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.