我正在使用 ui-screen-shooter ,它利用了 UI Automation JavaScript API截取应用程序的屏幕截图。我的应用程序在 iPad 和 iPhone 上的结构略有不同,因此我需要在我的 shoot_the_screen.js
脚本中检测设备类型并运行不同的代码。我想要等同于 [[UIDevice currentDevice] userInterfaceIdiom]
的东西,我可以在 JavaScript 中使用它。这是我想到的最好的。它有效,但您是否知道一种更简洁、对设备依赖性更低的方法来获取相同的信息?
var target = UIATarget.localTarget();
var width = target.rect().size.width;
if (width == 1024 || width == 768)
{
// iPad
}
else
{
// iPhone
}
最佳答案
您可以在目标上调用model()
来获取您需要的信息。这正是I'm doing in the ui-screen-shooter本身。
var modelName = UIATarget.localTarget().model();
// This prints "iPhone" or "iPad" for device. "iPhone Simulator" and "iPad Simulator" for sim.
UIALogger.logMessage(modelName);
关于javascript - 使用 UI 自动化检测设备类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22276789/