以编程方式从连接的Mac计算机获取iOS设备屏幕截图

问题描述:

我知道可以从iOS应用程序中的代码以编程方式获取屏幕截图,并手动从Xcode和Instruments获取屏幕截图(Instruments也会在UIAutomation测试失败期间自动截取屏幕截图)。我想要找到的是一种编程方式(在Mac上运行代码,而不是设备)从设备上截取插入到Mac上的屏幕截图。

I know it's possible to get a screenshot programatically from code in the iOS application, and to manually get screenshots from Xcode and Instruments (Instruments also automatically takes screenshots during UIAutomation test failures). What I would like to find is a programatic way (with code running on the Mac, not the device) to grab screenshots from the device onto the Mac which it is plugged into.

Xcode或Instruments中是否有API(或命令行参数)才能访问此屏幕截图功能?或者(理想情况下)与设备接口并直接获取屏幕截图,就像Xcode和Instruments一样吗?

Is there an API (or command-line parameters) into Xcode or Instruments to get access to this screenshot feature? Or (ideally) to interface to the device and get a screenshot directly, the same way that Xcode and Instruments do it?

是的,有办法。您想要安装免费的libimobiledevice库: https://github.com/benvium/libimobiledevice-macosx

Yes, there is a way. You want to install the free libimobiledevice library: https://github.com/benvium/libimobiledevice-macosx

安装后,您可以从命令行运行 idevicescreenshot ,它将保存一个TIFF文件截图到当前目录。

When it is installed, you can run idevicescreenshot from the commandline and it will save a TIFF file with a screenshot to the current directory.

参见 http://pervasivecode.blogspot.de/2012/06/take-iphone-or-ipad-screenshot-from.html