調用UIGetScreenImage()的時候,當我的應用程序中輸入的背景下,出現如下錯誤信息:得到錯誤的背景
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]'裏面有什麼? – zoul
CGImageRef UIGetScreenImage(void); (void)getIamge {CGImageRef screen = UIGetScreenImage(); UIImage * image = [UIImage imageWithCGImage:screen]; CGImageRelease(screen); UIImageWriteToSavedPhotosAlbum(image,self,nil,nil); NSLog(@「1」); [NSThread sleepForTimeInterval:0.5]; } –
最好將代碼添加到問題中,這很難在評論中閱讀。我已經編輯了該問題併爲您添加了缺少的代碼,現在可以刪除該評論。 – zoul