Method: EmergeCLI::XcodePhysicalDevice#install_app

Defined in:
lib/utils/xcode_physical_device.rb

#install_app(ipa_path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/utils/xcode_physical_device.rb', line 15

def install_app(ipa_path)
  raise "Non-IPA file provided: #{ipa_path}" unless ipa_path.end_with?('.ipa')

  Logger.info "Installing app to device #{@device_id}..."

  begin
    # Set a timeout since I've noticed xcrun devicectl can occasionally hang for invalid apps
    Timeout.timeout(60) do
      command = "xcrun devicectl device install app --device #{@device_id} \"#{ipa_path}\""
      Logger.debug "Running command: #{command}"

      output = `#{command} 2>&1`
      Logger.debug "Install command output: #{output}"

      if output.include?('ERROR:') || output.include?('error:')
        if output.include?('This provisioning profile cannot be installed on this device')
          bundle_id = extract_bundle_id_from_error(output)
          raise "Failed to install app: The provisioning profile for #{bundle_id} is not " \
                "valid for this device. Make sure the device's UDID is included in the " \
                'provisioning profile.'
        elsif output.include?('Unable to Install')
          error_message = output.match(/Unable to Install.*\n.*NSLocalizedRecoverySuggestion = ([^\n]+)/)&.[](1)
          check_device_compatibility(ipa_path)
          raise "Failed to install app: #{error_message || 'Unknown error'}"
        else
          check_device_compatibility(ipa_path)
          raise "Failed to install app: #{output}"
        end
      end

      success = $CHILD_STATUS.success?
      unless success
        check_device_compatibility(ipa_path)
        raise "Installation failed with exit code #{$CHILD_STATUS.exitstatus}"
      end
    end
  rescue Timeout::Error
    raise 'Installation timed out after 30 seconds. The device might be locked or ' \
          'installation might be stuck. Try unlocking the device and trying again.'
  end

  true
end