class DeviceAPI::IOS::IDeviceProvision

Namespace for all methods encapsulating ideviceprovision calls

Public Class Methods

get_profile_info(file) click to toggle source

Gets information about a provisioning profile @param [String] file path to the provisioning profile @return [Hash] hash containing provisioning profile information

# File lib/device_api/ios/ideviceprovision.rb, line 74
def self.get_profile_info(file)
  result = execute("ideviceprovision dump #{file}")

  raise IDeviceProvisionError.new(result.stderr) if result.exit != 0

  lines = result.stdout.split("\n")

  info = {}
  lines.each do |l|
    if /(.*):\s+(.*)/.match(l)
      info[Regexp.last_match[1]] = Regexp.last_match[2]
    end
  end
  info
end
has_profile?(options = {}) click to toggle source

Checks to see if a profile is installed on the specified device @param [Hash] options options used for checking profiles @option options [String] :name name of the profile (optional when uuid provided) @option options [String] :uuid UUID of the profile (optional when name provided) @option options [String] :serial serial of the device to check @return [Boolean] true if the profile is installed, false otherwise

# File lib/device_api/ios/ideviceprovision.rb, line 24
def self.has_profile?(options = {})
  name = options[:name]
  uuid = options[:uuid]
  serial = options[:serial]

  profiles = list_profiles(serial)

  profiles.key?(uuid) || profiles.value?(name)
end
install_profile(options = {}) click to toggle source

Installs the specified profile to the device @param [Hash] options options used for installing a profile @option options [String] :file path to the provisioning profile @option options [String] :serial serial of the device to install the profile to @return [Boolean, IDeviceProvisionError] true if the profile is installed, an error otherwise

# File lib/device_api/ios/ideviceprovision.rb, line 56
def self.install_profile(options = {})
  serial = options[:serial]
  file = options[:file]

  info = get_profile_info(file)

  # Check to see if the profile has already been added to the device
  return true if has_profile?(serial: serial, uuid: info['UUID'])

  result = execute("ideviceprovision -u #{serial} install #{file}")

  raise IDeviceProvisionError.new(result.stderr) if result.exit != 0
  true
end
list_profiles(serial) click to toggle source

Lists all profiles on the specified device @param [String] serial serial of the device to check @return [Hash] hash of profile name and UUID

# File lib/device_api/ios/ideviceprovision.rb, line 10
def self.list_profiles(serial)
  result = execute("ideviceprovision -u #{serial} list")

  raise IDeviceProvisionError.new(result.stderr) if result.exit != 0

  Hash[result.stdout.split("\n").map { |a| b = a.split(' - '); [b[0], b[1]] }[1..-1]]
end
remove_profile(options = {}) click to toggle source

Removes the specified profile from the device @param [Hash] options options used for removing a profile @option options [String] :uuid UUID of the profile to be removed @option options [String] :serial serial of the device to remove the profile from @return [Boolean, IDeviceProvisionError] true if the profile is removed from the device, an error otherwise

# File lib/device_api/ios/ideviceprovision.rb, line 39
def self.remove_profile(options = {})
  uuid = options[:uuid]
  serial = options[:serial]

  return true unless has_profile?(serial: serial, uuid: uuid)

  result = execute("ideviceprovision -u #{serial} remove #{uuid}")

  raise IDeviceProvisionError.new(result.stderr) if result.exit != 0
  true
end