如何以编程方式截取iPhone主屏幕的屏幕截图

问题描述:

是否可以从我的应用程序内部以编程方式截取主屏幕

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

谢谢!

使用私有API是的。 UIGetScreenImage()也可以在应用程序在后台运行时使用。我设置了一个应用程序,以便在抛出异常时截取屏幕截图,并且还会在后台运行时崩溃时显示主屏幕/其他应用程序的屏幕截图。

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.

这个问题有一些有关来自AppStore的DisplayRecorder应用程序的有趣答案: iOS应用显示记录器如何记录屏幕而不使用私有API?

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?

这显示了如何使用UIGetScreenImage: http://stackoverflow.com/a/2507740/832065

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



更新:

_UICreateScreenUIImage $ c>是一个快得多的截图方法。它也返回一个UIImage而不是CGImageRef:

_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;