Method: FastlaneCore::DeviceManager.connected_devices

Defined in:
fastlane_core/lib/fastlane_core/device_manager.rb

.connected_devices(requested_os_type) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'fastlane_core/lib/fastlane_core/device_manager.rb', line 69

def connected_devices(requested_os_type)
  UI.verbose("Fetching available connected devices")

  device_types = if requested_os_type == "tvOS"
                   ["AppleTV"]
                 elsif requested_os_type == "iOS"
                   ["iPhone", "iPad", "iPod"]
                 else
                   []
                 end

  devices = [] # Return early if no supported devices are being searched for
  if device_types.count == 0
    return devices
  end

  usb_devices_output = ''
  Open3.popen3("system_profiler SPUSBDataType -xml") do |stdin, stdout, stderr, wait_thr|
    usb_devices_output = stdout.read
  end

  device_uuids = []
  result = Plist.parse_xml(usb_devices_output)

  discover_devices(result[0], device_types, device_uuids) if result[0]

  if device_uuids.count > 0 # instruments takes a little while to return so skip it if we have no devices
    instruments_devices_output = ''
    Open3.popen3("instruments -s devices") do |stdin, stdout, stderr, wait_thr|
      instruments_devices_output = stdout.read
    end

    instruments_devices_output.split(/\n/).each do |instruments_device|
      device_uuids.each do |device_uuid|
        match = instruments_device.match(/(.+) \(([0-9.]+)\) \[(\h{40}|\h{8}-\h{16})\]?/)
        if match && match[3].delete("-") == device_uuid
          devices << Device.new(name: match[1], udid: match[3], os_type: requested_os_type, os_version: match[2], state: "Booted", is_simulator: false)
          UI.verbose("USB Device Found - \"" + match[1] + "\" (" + match[2] + ") UUID:" + match[3])
        end
      end
    end
  end

  return devices
end