Get a screenshot while App is in background? (Priv

2019-04-02 07:44发布

I am developing a monitoring application for the iPad. It already uses private frameworks to send artificial events and simulate user input, while my App is on the background and another App on the foreground.

Now my problem is, I need to get a screenshot of the iPad as an image programatically. I know the UIGetScreenImage method, and also rendering every view on the screen to get the image. However, UIGetScreenImage cannot be called from the background. (I get an error telling me that when I try it from the background) And I cannot render the views from another App, since I only know my App's views.

OPTION 1 I am able to simulate a click on the home and lock keys, for the iPad to generate a screenshot. Afterwards, I use private APIs to access this image from the photoalbum, using the [PLPhotoLibrary](https://github.com/nst/iOS-Runtime-Headers/blob/3686717e107fa36a990fac20c30da2da9a25b698/PrivateFrameworks/PhotoLibrary.framework/PLPhotoLibrary.h ), PLPhotoAlbum and PLPhoto.

id lib = [PLPhotoLibrary sharedPhotoLibrary];
id allPhotosAlbum = [lib allPhotosAlbum];
id contents = [lib albumContents];
id lastPhoto = [contents objectAtIndex:[contents count] -1];
UIImage *screenshot = [lastPhoto newFullSizeImage];

The only problem with this approach is that the screenshots will stack up ont he album, filling the iPad's memory. So either I need another way, or I need a way to delete this pictures. But, when I call the delete methods in the photo album and photo library, I get a "SQLITE error 8 [attempt to write to readonly database]

Any suggestions on how to achieve this screenshot thing in a better way would be appreciated.

I will not be uploading this App to the App store. It is for private use.

4条回答
聊天终结者
2楼-- · 2019-04-02 08:27

It used to be that you could capture a screen-shot of the entire device screen, from the foreground or the background, using IOSurface. Apple blocked that API in iOS 9. It's no longer possible without jail breaking your device, private API or not.

查看更多
▲ chillily
3楼-- · 2019-04-02 08:32

You can use following private API: [[UIWindow class] performSelector:@selector(createScreenIOSurface)];

查看更多
劳资没心,怎么记你
4楼-- · 2019-04-02 08:36

After massive testing and trying, I concluded that even with private APIs erasing the photos from the photo album is too much of a problem, maybe even impossible. I ended up writing a script that simulates user inputs and erases the photos.

查看更多
Explosion°爆炸
5楼-- · 2019-04-02 08:41

Jailbreaking your device is probably the only recourse, not that I recommend doing that.

However, Apple never intended for people, developer or not, to use their iPad in the manner you describe.

查看更多
登录 后发表回答