How to get iOS device information ( UDID, Device Name and Device Version) using java code

Hi,

I am unable to get iPhone device information( UDID, Device Name and Device Version) Using Java Code in mac machine. Is it possible to get the iOS device information using java code in mac machine. This is priority work for me. Please help me any one.

Thanks in advance.

1 Like

You can try the following:

    driver.getCapabilities().getCapability("udid")
    driver.getCapabilities().getCapability("deviceName")
    driver.getCapabilities().getCapability("platformVersion")

Works for Windows machine and Android device.
Even if you provided a false version when creating driver (or didn’t
provide any), Appium will correct it when opening the session. Just make
sure it is written after the driver = new AnroidDriver… line.

Hi Alexis,

Thanks for Reply, Actually I am trying to get iPhone device which is connected to mac machine using java code by sending commands to the terminal. After that passing UDID, Device Name and Device Version to capabilities. Currently I am trying to the below ways, but not displaying anything in console.

Code 1:
String[] arguments = new String[] {"/usr/local/bin/mobiledevice", “list_devices”};
Process p =Runtime.getRuntime().exec(arguments);
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = “”;
String allLine = “”;

while((line=r.readLine()) != null)
{
System.out.println(line);

}

Code 2:
String[] str = {"/bin/bash", “-c”, “ios-deploy -c”};
Process p = Runtime.getRuntime().exec(str);
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = “”;
String allLine = “”;
while((line=r.readLine()) != null)
{
System.out.println(line);
}

Please correct me if I am doing wrong.

Hi,

Try this to get device udid,

Process p = Runtime.getRuntime().exec(“idevice_id -l”);

Regards,
Bhaskar.

Hi bhaskar,

Thanks for reply.

Could you please tell me, how to start iOS webkit debug proxy server programmatically using java code.

@bhaskar: the mentioned cmd would display the list of devices that are connected , how would you identify if there are no of devices that are connected

Hi @bhaskar
Am trying to retrieve IOS device info from MAC and Windows. In Terminal if i execute command “idevice_id -l” am able to get my device id . But when trying to execute through Runtime.getRuntime.exec(“idevice_id -l”) it is returning error No such file or directory.
Could you please give me some inputs on this.