在应用程序处于后台时获取屏幕截图? (允许私有API) [英] Get a screenshot while App is in background? (Private APIs allowed)

查看:586
本文介绍了在应用程序处于后台时获取屏幕截图? (允许私有API)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPad开发监控应用程序。它已经使用私有框架发送人工事件并模拟用户输入,而我的应用程序在后台,另一个应用程序在前台。

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.

现在我的问题是,我需要以编程方式获取iPad的屏幕截图。我知道UIGetScreenImage方法,并且还渲染屏幕上的每个视图以获取图像。但是,无法从后台调用UIGetScreenImage。 (当我从后台尝试时,我收到错误告诉我)我无法从另一个应用程序渲染视图,因为我只知道我的应用程序的视图。

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
我可以模拟家中的点击并锁定按键,iPad可以生成屏幕截图。之后,我使用私有API从photoalbum访问此图像,使用[PLPhotoLibrary](https://github.com/nst/iOS-Runtime-Headers/blob/3686717e107fa36a990fac20c30da2da9a25b698/PrivateFrameworks/PhotoLibrary.framework/PLPhotoLibrary.h
), PLPhotoAlbum PLPhoto

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

这种方法的唯一问题是截图将叠加在他的专辑上,填满了iPad的记忆。所以要么我需要另一种方式,要么我需要一种方法来删除这些图片。但是,当我调用相册和照片库中的删除方法时,我得到一个SQLITE错误8 [尝试写入只读数据库]

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.

我不会将此应用程序上传到App商店。它是供私人使用的。

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

推荐答案

经过大量测试和尝试后,我得出结论,即使使用私有API擦除相册中的照片也是一个太大的问题,甚至可能是不可能。
我最终编写了一个模拟用户输入并擦除照片的脚本。

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.

这篇关于在应用程序处于后台时获取屏幕截图? (允许私有API)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆