SnapshotViewAfterScreenUpdates on UIScreen gives a blank snapshot on the device

I try to get an image of the entire screen when the user sees it. The following code should work, but it will only work in the simulator. What do I need to do for this to work on a device running iOS 8.1?

UIView *snapshot = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES]; CGSize outputSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); UIGraphicsBeginImageContextWithOptions(outputSize, NO, 0); [snapshot drawViewHierarchyInRect:CGRectMake(0.0, 0.0, outputSize.width, outputSize.height) afterScreenUpdates:YES]; UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

I am happy to try alternative strategies, but the key is what I want, as the user sees it - the keyboard and that’s it.

Greetings

+6
source share
1 answer
 UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)), NO, 1.0f); [self.view drawViewHierarchyInRect:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) afterScreenUpdates:NO]; UIImage *snapshotImage = UIGraphicsGetImageFromCurrentImageContext(); 
+1
source

Source: https://habr.com/ru/post/980581/


All Articles