Method: EmergeCLI::XcodePhysicalDevice#launch_app

Defined in:
lib/utils/xcode_physical_device.rb

#launch_app(bundle_id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/utils/xcode_physical_device.rb', line 59

def launch_app(bundle_id)
  command = "xcrun devicectl device process launch --device #{@device_id} #{bundle_id}"
  Logger.debug "Running command: #{command}"

  begin
    Timeout.timeout(30) do
      output = `#{command} 2>&1`
      success = $CHILD_STATUS.success?

      unless success
        Logger.debug "Launch command output: #{output}"
        if output.include?('The operation couldn\'t be completed. Application is restricted')
          raise 'Failed to launch app: The app is restricted. Make sure the device is ' \
                'unlocked and the app is allowed to run.'
        elsif output.include?('The operation couldn\'t be completed. Unable to launch')
          raise 'Failed to launch app: Unable to launch. The app might be in a bad state - ' \
                'try uninstalling and reinstalling.'
        else
          raise "Failed to launch app #{bundle_id} on device: #{output}"
        end
      end
    end
  rescue Timeout::Error
    raise 'Launch timed out after 30 seconds. The device might be locked. ' \
          'Try unlocking the device and trying again.'
  end

  true
end