Module: SimCtl::Command::Launch

Included in:
SimCtl::Command
Defined in:
lib/simctl/command/launch.rb

Constant Summary collapse

SUPPORTED_SCALE =
[1.0, 0.75, 0.5, 0.25].freeze

Instance Method Summary collapse

Instance Method Details

#launch_app(device, identifier, args = [], opts = {}) ⇒ void

This method returns an undefined value.

Launches an app in the given device

Parameters:

  • device (SimCtl::Device)

    the device to launch

  • opts (Hash) (defaults to: {})

    options hash - ‘{ wait_for_debugger: true/false }`

  • identifier (String)

    the app identifier

  • args (Array) (defaults to: [])

    optional launch arguments



35
36
37
38
39
# File 'lib/simctl/command/launch.rb', line 35

def launch_app(device, identifier, args = [], opts = {})
  launch_args = args.map { |arg| Shellwords.shellescape arg }
  launch_opts = opts[:wait_for_debugger] ? '-w' : ''
  Executor.execute(command_for('launch', launch_opts, device.udid, identifier, launch_args))
end

#launch_device(device, scale = 1.0, opts = {}) ⇒ void

This method returns an undefined value.

Launches a Simulator instance with the given device

Parameters:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simctl/command/launch.rb', line 12

def launch_device(device, scale = 1.0, opts = {})
  raise "unsupported scale '#{scale}' (supported: #{SUPPORTED_SCALE.join(', ')})" unless SUPPORTED_SCALE.include?(scale)
  # Launching the same device twice does not work.
  # Simulator.app would just hang. Solution: Kill first.
  kill_device(device)
  args = {
    '-ConnectHardwareKeyboard' => 1,
    '-CurrentDeviceUDID' => device.udid,
    "-SimulatorWindowLastScale-#{device.devicetype.identifier}" => scale
  }
  args['-DeviceSetPath'] = Shellwords.shellescape(SimCtl.device_set_path) unless SimCtl.device_set_path.nil?
  args = args.merge(opts).zip.flatten.join(' ')
  command = "open -Fgn #{Xcode::Path.home}/Applications/Simulator.app --args #{args}"
  system command
end