CALayer renderInContext: causes an unknown failure

The entire code block consists of the following:

CGSize layerSize = [webview sizeThatFits:CGSizeZero]; if ([UIScreen instancesRespondToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0f) { UIGraphicsBeginImageContextWithOptions(layerSize, NO, 2.0f); } else { UIGraphicsBeginImageContext(layerSize); } [webview.layer renderInContext:UIGraphicsGetCurrentContext()]; screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

but after testing this line causes a problem:

  [webview.layer renderInContext:UIGraphicsGetCurrentContext()]; 

The application shuts down for no reason listed in the console, and using @try @catch @finally fails. I imported Quartzcore into AppDelegate.h if this has anything to do with it. The application works fine in the simulator, but it crashes when working on a real device.

+6
source share
2 answers

@Greg: there seems to be a problem with memory overflow on the device, since the device is limited by memory, while the simulator works with a different memory configuration, I am in the same place - this can happen for long web pages, any ideas how to solve them?

Anyone who is the maximum width and height [CALayer renderInContext] can handle on the device itself (iphone retina or not retina) before it works?

+3
source

try

 [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
0
source

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


All Articles