【发布时间】:2012-10-18 07:03:56
【问题描述】:
当我的应用进入后台时,出现如下错误信息:
012-10-18 14:38:05.964 SoundRecorder[693:14603] *** Terminating app due to uncaught
exception 'NSGenericException', reason: 'Cannot call UICreateScreenImage() while app
is in the background.'
这是我的代码:
- (void) getImage
{
CGImageRef screen = UIGetScreenImage();
UIImage* image = [UIImage imageWithCGImage:screen];
CGImageRelease(screen);
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
NSLog(@"1");
[NSThread sleepForTimeInterval:0.5];
}
- (void) applicationDidEnterBackground: (UIApplication*) application
{
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while(1){
[self getImage];
if(breakpoints != 1)
break;
}
NSLog(@"run at backgroud!");
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
【问题讨论】:
-
[self getImage]里面有什么? -
CGImageRef UIGetScreenImage(void); -(void)getIamge{ CGImageRef screen = UIGetScreenImage(); UIImage* 图像 = [UIImage imageWithCGImage:screen]; CGImageRelease(屏幕); UIImageWriteToSavedPhotosAlbum(图像,自我,无,无); NSLog(@"1"); [NSThread sleepForTimeInterval:0.5]; }
-
最好把代码加到问题里,在cmets里很难看懂。我已经为您编辑了问题并添加了缺少的代码,您现在可以删除评论。
标签: iphone