当我的应用进入后台时,出现如下错误信息:</p>
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;
});
}