Is iPhone status screen capture enabled?

I'm looking for a way to take a screenshot on an iPhone with the top status bar turned on. I am currently using the following code:

UIGraphicsBeginImageContext(self.view.bounds.size); //self.view.window.frame.size [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

The above code successfully takes a screenshot of the iPhone UIView, but does not include the top status bar (in its place, it's just a 20px space).

+6
objective-c iphone screenshot
source share
4 answers

As in iOS 7, you can do this without using private APIs using

 UIView *screenshotView = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:NO]; 

See my answer to this question:

Moving the status bar in iOS 7

+11
source share

You can get all the contents of the screen by calling the private UIGetScreenImage API. See the previous answer to a similar question for more information.

+3
source share

Since October 8, 2009, the use of UIGetScreenImage has rejected my application! :( I would not recommend using it. I believe that Apple is trying to clean all applications and bring them into line with the new 3.x OS / API. I’m looking for an alternative. If anyone are there any suggestions. API?

+1
source share

Instead of using a private API, why not display the entire UIWindow interface in an image context? This may be enough to replace self.view with self.view.window in your code.

You can also get the current window as an instance property of [UIApplication sharedApplication] . The status bar may be on a separate layer of the window, and you may need to render the windows in order.

Something like that:

 UIGraphicsBeginImageContext(self.view.window.frame.size); for (UIWindow *window in [[UIApplication sharedApplication] windows]) { [window.layer renderInContext:UIGraphicsGetCurrentContext()]; } UIImage *screenshotImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

In any case, you probably don't need to access the private API.

+1
source share

All Articles