Search code examples
iosscreenshot

iOS: can I take screenshot on global queue?


I wonder how can I take a screenshot in a global queue? right now I'm doing it in the main queue and it works, if I do it in the global queue, things freeze. I'm using this screenshot code: iOS: what's the fastest, most performant way to make a screenshot programmatically? I also tried the following code to take the snapshot of self.view, but it also doesn't work:

+(UIImage *)snapshot_of_view:(UIView*)view {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

any ideas?


Solution

  • Any UI operation MUST be performed in the main thread.