Question

I am using ui-screen-shooter, which makes use of the UI Automation JavaScript API to take screenshots of apps. My app has a slightly different structure on iPad and iPhone, so I need to detect the device type in my shoot_the_screen.js script and run different code. I would like something equivalent to [[UIDevice currentDevice] userInterfaceIdiom] that I can use in JavaScript. Here is the best I have come up with. It works, but do you know of a cleaner, less device-dependent way to get the same information?

var target = UIATarget.localTarget();

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

if (width == 1024 || width == 768)
{
    // iPad
}
else
{
    // iPhone
}
Was it helpful?

Solution

You can call model() on the target to get the information you need. That's exactly what I'm doing in the ui-screen-shooter itself.

var modelName = UIATarget.localTarget().model();

// This prints "iPhone" or "iPad" for device. "iPhone Simulator" and "iPad Simulator" for sim.
UIALogger.logMessage(modelName);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top