Search code examples
c#iosdynamicudid

Get UDID of iOS Simulators programmatically using c#


I am using c# visual studio to automate iOS apps and the simulators UDID gets changed every time, I do not want to manually type the UDID of simulator every-time... I need help where the system automatically gets the UDID of the booted simulator


Solution

  • You can launch from C# a system tool simctl , to see manual page, launch in Terminal:

    xcrun simctl help
    

    You can get list of devices in JSON format and find device with state Booted:

    xcrun simctl list --json devices available
    
    <...>
    {
            "dataPath" : "\/Users\/admin\/Library\/Developer\/CoreSimulator\/Devices\/2BE68BC5-02C0-4B1C-92EC-E80CCE713144\/data",
            "logPath" : "\/Users\/admin\/Library\/Logs\/CoreSimulator\/2BE68BC5-02C0-4B1C-92EC-E80CCE713144",
            "udid" : "2BE68BC5-02C0-4B1C-92EC-E80CCE713144",
            "isAvailable" : true,
            "deviceTypeIdentifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-12-Pro-Max",
            "state" : "Booted",
            "name" : "iPhone 12 Pro Max"
          },
    <....>
    

    Or in less convenient for C# way:

    xcrun simctl list | grep Booted
    

    You can find path to xcrun with:

    which xcrun