【问题标题】:Detect device type with UI Automation使用 UI 自动化检测设备类型
【发布时间】:2014-04-12 04:13:52
【问题描述】:

我正在使用ui-screen-shooter,它使用UI Automation JavaScript API 来截取应用程序的屏幕截图。我的应用在 iPad 和 iPhone 上的结构略有不同,因此我需要在我的 shoot_the_screen.js 脚本中检测设备类型并运行不同的代码。我想要可以在 JavaScript 中使用的等同于 [[UIDevice currentDevice] userInterfaceIdiom] 的东西。这是我想出的最好的。它有效,但您知道获取相同信息的更简洁、更少依赖设备的方法吗?

var target = UIATarget.localTarget();

var width = target.rect().size.width;

if (width == 1024 || width == 768)
{
    // iPad
}
else
{
    // iPhone
}

【问题讨论】:

    标签: javascript ios automation ios-ui-automation


    【解决方案1】:

    您可以在目标上调用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);
    

    【讨论】:

    • 当我在模拟器中运行时,它会为我打印“iPhone Simulator”。
    • 啊,我明白了。您可以使用var isPhone = target.model().match(/iPhone/);,它将等于iPhonenull
    • 啊,对不起。应该提到它。我会更新答案。
    猜你喜欢
    • 2014-09-17
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多