从iOS应用程序截取屏幕截图 - 模拟显示记录器(在内部查询) [英] Taking Screenshots from iOS app - emulating Display recorder (query on the internals)

查看:198
本文介绍了从iOS应用程序截取屏幕截图 - 模拟显示记录器(在内部查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个iOS应用,可以截取其他应用,视频等截图,作为实验的一部分。我愿意使用私有API,因为我不会将应用程序发布到应用程序商店。我可以成功使用方法GetUIScreenImage()来拍摄当前屏幕(应用程序屏幕)的快照。

I need to create an iOS app which can take screenshots of other apps, videos etc. as a part of an experiment. I am open to using Private API's since I won't be publishing the app to the app store. I could successfully use the method GetUIScreenImage() to take snapshots of the current screen (app screen).

但是,由于沙箱限制,我无法截取屏幕截图在后台。我收到错误 - 当应用程序在后台时无法调用CreateUIScreenImage()。

However, due to sandbox restrictions I am not able to take screenshots while in the background. I get the error - "Cannot call CreateUIScreenImage() while the app is in background".

我参考了这篇文章 - iOS app Display Recorder如何在不使用私有API的情况下记录屏幕?建议使用IOMobileFramebuffer和IOSurface绕过沙箱限制,这个链接 - http://www.iphonesheep.com/2009/11/25/iphone%E2%80%99s-framebuffer-secrets-revealed/ 。但我无法获得创建和传输曲面的流程。非常感谢您对此主题的任何帮助。

I referred to this article - How does the iOS app Display Recorder record the screen without using private API? which suggested use of IOMobileFramebuffer and IOSurface to bypass sandbox restrictions, also this link - http://www.iphonesheep.com/2009/11/25/iphone%E2%80%99s-framebuffer-secrets-revealed/. But I am unable to get the flow of creating and transferring surfaces. Any help on this topic is highly appreciated.

此外,有没有办法在越狱设备的后台调用UIGetScreenImage()?

Also, is there a way to call UIGetScreenImage() in the background on a jailbroken device ?

更新:

我能够抓住主屏幕表面并将其放在应用层上,但我的用例是能够打开其他应用程序,并能够通过我创建的应用程序记录它们。我贴在我的应用图层上的表面是静态的。

Update:
I am able to get hold of the main screen surface and put it on the app layer, but my use case is to be able to open up other apps and be able to record them via the app I create. The surface I paste over my app layer is however static.

编辑

这是我的理解 - 连接到主显示层的主屏幕表面需要放在当前层上。在这样做之后,我应该能够浏览其他应用程序,从刚刚粘贴的表面打开它们。

edit
Here is what I understand - the main screen surface attached to the main display layer needs to be put on the current layer. After doing so, I should be able to browse through other apps, open them from the surface just pasted.

这是代码(它将主屏幕表面放在顶部应用程序层但我无法使用该表面,即打开应用程序等。):

Here is the code (It puts the main screen surface on top of app layer but I am unable to use that surface i.e, open up apps etc.):

IOMobileFramebufferConnection connect;
kern_return_t result;
CoreSurfacebufferRef screenSurface = NULL;
io_service_t framebufferService = IOServiceGetMatchingService (kIOMasterPortDefault, IOServiceMatching ("AppleH1CLCD"));
if(!framebufferService)
        io_service_t framebufferService = IOServiceGetMatchingService (kIOMasterPortDefault, IOServiceMatching ("AppleM2CLCD"));
if(!framebufferService)
        io_service_t framebufferService = IOServiceGetMatchingService (kIOMasterPortDefault, IOServiceMatching ("AppleCLCD"));
result = IOMobileFramebufferOpen( framebufferService, mach_task_self(), 0 , &connect);
result = IOMobileFramebufferGetLayerDefaultSurface(connect, 0, &screenSurface);

CALayer *Layer;
Layer = [CALayer layer];
[Layer setFrame: CGRectMake(0, 0, 768, 1024)];
[Layer setOpaque:YES];
IOSurfaceLock(screenSurface, 0, NULL);
[Layer setContents: (_bridge id)(screenSurface)];
IOSurfaceUnlock(screenSurface, 0, NULL);
[self.view.layer addSublayer:Layer];

我知道我错过了什么,做错了什么。如果你能指出这一点会很有帮助。

I know i am missing out something and doing something wrong. It would be great help if you could point that out.

更新

我想我可能错了我的基本假设。

1.我假设 - >应用程序交换曲面(或图层),以便用户现在可以在主屏幕上浏览。应用程序永远不会移动到后台。

2.听起来更正确 - >应用移动到后台。获取屏幕上最顶部的表面,从中创建图像并保存。
请澄清。

update
I think I may be wrong in my fundamental assumption.
1. What I assume -> The app swaps the surfaces (or layers) so that the user can now browse on the main screen. The app never moves to the background.
2. What sounds more correct -> The app moves to the background. Gets the topmost surface on screen, creates an image out of it and saves it. Please clarify.

推荐答案

获取创建和转移表面的流程究竟出现了什么问题?你可以发布正在使用的代码,并指出哪一行不起作用。

What is exactly the problem with "get the flow of creating and transferring surface"? Can you post the code which are using and point out which line doesn't work.

对于越狱设备:

转到/ Application / XCode / Content / Developer / Platforms并使用grep来查找在应用程序处于后台时无法调用CreateUIScreenImage()的句子。你会在某个框架中找到它(我假设是UIKit)。接下来,您可以反汇编它,您将找到在后台进行屏幕截图所需的一些权利。

Go to /Application/XCode/Content/Developer/Platforms and grep it for the sentence "Cannot call CreateUIScreenImage() while the app is in background". You will find it in some framework (I assume UIKit). Next, you can disassemble it and you will find some entitlement which is required to do screenshots in the background.

您可以在这里查看如何使用ldid for jailbroken设备的权利:
iOS如何使用Entitlement.plist指定我的应用程序的属性

And you can look here how to use entitlements with ldid for jailbroken device: iOS How to use Entitlement.plist to specify property of my app

这篇关于从iOS应用程序截取屏幕截图 - 模拟显示记录器(在内部查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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