我正在使用以下代码将Cocos2d图层的屏幕截图保存到相机胶卷..
-(void) takeScreenshot {
[self turnAllNotesBlack];
CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *img = [self screenshotWithStartNode:n];
//NSParameterAssert(img);
UIImageWriteToSavedPhotosAlbum(img,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
[self resetIlluminatedNotes];
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Save failed"
message: @"Failed to save image"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
它在模拟器上工作正常,但是当我在手机上运行时,它会调用错误方法,并且不会保存图片。
有谁知道这是为什么?
卡尔
答案 0 :(得分:3)
我不得不去'设置 - >隐私 - >照片'并为我的新应用启用照片..