1

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

screenshot

Thanks!

vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
ytpm
  • 4,962
  • 6
  • 56
  • 113

1 Answers1

5

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;
Community
  • 1
  • 1
JonasG
  • 9,274
  • 12
  • 59
  • 88
  • 2
    Please note that using a private API will get the app rejected when it is submitted to the App store. – James Thiele Nov 19 '12 at 18:55
  • 1
    Yeah thats obvious... Its not necessary to mention every time that Private APIs are rejected by apple. Dynamic loading of Private Frameworks at runtime (dlopen?) or something similar can sneak past apple's static analyzer – JonasG Nov 19 '12 at 18:56
  • 1
    At least in iOS7, `UIGetScreenImage()` doesn't work in the background, you clearly get a message in the log that you can't do so if you try. However, before you get effectively in background mode, the last image you can get is the springboard (as you're leaving your app), but nothing after that unfortunately. – Frank Dec 19 '13 at 03:04
  • _UICreateScreenUIImage gives me a black image. Does this API still work? – EmilyJ Mar 02 '16 at 09:08
  • @EmilyJ any success? – Benj Oct 26 '16 at 19:58