How can I take a screenshot of the iPhone home scr

2019-01-15 11:22发布

问题:

Is it possible to take a screenshot of the Home Screen programmatically from inside of my application?

Thanks!

回答1:

Using Private APIs yes. UIGetScreenImage() also works when the app is running in the background. I set up an app to take a screenshot whenever an exception is thrown, and it also takes screenshots of the home screen/ other apps when it crashes while running in the background.

This question has some interesting answers regarding the DisplayRecorder app from the AppStore: How does the iOS app Display Recorder record the screen without using private API?

And this shows you how to use UIGetScreenImage: https://stackoverflow.com/a/2507740/832065


Update:

_UICreateScreenUIImage() is a much faster method of getting a screenshot. It also returns a UIImage instead of CGImageRef:

OBJC_EXTERN UIImage *_UICreateScreenUIImage(void) NS_RETURNS_RETAINED;