Getting errors when calling UIGetScreenImage() in background
<p>when my application enter background , Appear as follows error information：</p>

<pre><code>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.'
</code></pre>

<p>this is my code:</p>

<pre><code>- (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;  
     }); 
}
</code></pre>
