Class: AppInfo::MobileProvision

Inherits:
Object
  • Object
show all
Defined in:
lib/app_info/mobile_provision.rb

Overview

.mobileprovision file parser

Defined Under Namespace

Classes: DeveloperCertificate

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MobileProvision

Returns a new instance of MobileProvision.



9
10
11
# File 'lib/app_info/mobile_provision.rb', line 9

def initialize(path)
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



214
215
216
217
218
# File 'lib/app_info/mobile_provision.rb', line 214

def method_missing(method_name, *args, &block)
  mobileprovision.try(:[], Util.format_key(method_name)) ||
    mobileprovision.send(method_name) ||
    super
end

Instance Method Details

#[](key) ⇒ Object



195
196
197
# File 'lib/app_info/mobile_provision.rb', line 195

def [](key)
  mobileprovision.try(:[], key.to_s)
end

#adhoc?Boolean

Returns:

  • (Boolean)


106
107
108
109
110
# File 'lib/app_info/mobile_provision.rb', line 106

def adhoc?
  return false if platform == :macos # macOS no need adhoc

  !development? && !devices.nil?
end

#app_nameObject



17
18
19
# File 'lib/app_info/mobile_provision.rb', line 17

def app_name
  mobileprovision.try(:[], 'AppIDName')
end

#appstore?Boolean

Detect app store type

related link: developer.apple.com/library/archive/qa/qa1830/_index.html

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
103
104
# File 'lib/app_info/mobile_provision.rb', line 95

def appstore?
  case platform.downcase.to_sym
  when :ios
    !development? && entitlements.key?('beta-reports-active')
  when :macos
    !development?
  else
    raise Error, "Not implement with platform: #{platform}"
  end
end

#created_dateObject



57
58
59
# File 'lib/app_info/mobile_provision.rb', line 57

def created_date
  mobileprovision.try(:[], 'CreationDate')
end

#developer_certsObject



69
70
71
72
73
74
75
76
# File 'lib/app_info/mobile_provision.rb', line 69

def developer_certs
  certs = mobileprovision.try(:[], 'DeveloperCertificates')
  return if certs.empty?

  certs.each_with_object([]) do |cert, obj|
    obj << DeveloperCertificate.new(cert)
  end
end

#development?Boolean

Detect is development type of mobileprovision

related link: stackoverflow.com/questions/1003066/what-does-get-task-allow-do-in-xcode

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
# File 'lib/app_info/mobile_provision.rb', line 81

def development?
  case platform.downcase.to_sym
  when :ios
    entitlements['get-task-allow'] == true
  when :macos
    !devices.nil?
  else
    raise Error, "Not implement with platform: #{platform}"
  end
end

#devicesObject



41
42
43
# File 'lib/app_info/mobile_provision.rb', line 41

def devices
  mobileprovision.try(:[], 'ProvisionedDevices')
end

#empty?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/app_info/mobile_provision.rb', line 199

def empty?
  mobileprovision.nil?
end

#enabled_capabilitiesObject

Enabled Capabilites

Related link: developer.apple.com/support/app-capabilities/



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/app_info/mobile_provision.rb', line 122

def enabled_capabilities
  capabilities = []
  capabilities << 'In-App Purchase' << 'GameKit' if adhoc? || appstore?

  entitlements.each do |key, _|
    case key
    when 'aps-environment'
      capabilities << 'Push Notifications'
    when 'com.apple.developer.applesignin'
      capabilities << 'Sign In with Apple'
    when 'com.apple.developer.siri'
      capabilities << 'SiriKit'
    when 'com.apple.security.application-groups'
      capabilities << 'App Groups'
    when 'com.apple.developer.associated-domains'
      capabilities << 'Associated Domains'
    when 'com.apple.developer.default-data-protection'
      capabilities << 'Data Protection'
    when 'com.apple.developer.networking.networkextension'
      capabilities << 'Network Extensions'
    when 'com.apple.developer.networking.vpn.api'
      capabilities << 'Personal VPN'
    when 'com.apple.developer.healthkit',
         'com.apple.developer.healthkit.access'
      capabilities << 'HealthKit' unless capabilities.include?('HealthKit')
    when 'com.apple.developer.icloud-services',
         'com.apple.developer.icloud-container-identifiers'
      capabilities << 'iCloud' unless capabilities.include?('iCloud')
    when 'com.apple.developer.in-app-payments'
      capabilities << 'Apple Pay'
    when 'com.apple.developer.homekit'
      capabilities << 'HomeKit'
    when 'com.apple.developer.user-fonts'
      capabilities << 'Fonts'
    when 'com.apple.developer.pass-type-identifiers'
      capabilities << 'Wallet'
    when 'inter-app-audio'
      capabilities << 'Inter-App Audio'
    when 'com.apple.developer.networking.multipath'
      capabilities << 'Multipath'
    when 'com.apple.developer.authentication-services.autofill-credential-provider'
      capabilities << 'AutoFill Credential Provider'
    when 'com.apple.developer.networking.wifi-info'
      capabilities << 'Access WiFi Information'
    when 'com.apple.external-accessory.wireless-configuration'
      capabilities << 'Wireless Accessory Configuration'
    when 'com.apple.developer.kernel.extended-virtual-addressing'
      capabilities << 'Extended Virtual Address Space'
    when 'com.apple.developer.nfc.readersession.formats'
      capabilities << 'NFC Tag Reading'
    when 'com.apple.developer.ClassKit-environment'
      capabilities << 'ClassKit'
    when 'com.apple.developer.networking.HotspotConfiguration'
      capabilities << 'Hotspot'
    when 'com.apple.developer.devicecheck.appattest-environment'
      capabilities << 'App Attest'
    when 'com.apple.developer.coremedia.hls.low-latency'
      capabilities << 'Low Latency HLS'
    when 'com.apple.developer.associated-domains.mdm-managed'
      capabilities << 'MDM Managed Associated Domains'
    # macOS Only
    when 'com.apple.developer.maps'
      capabilities << 'Maps'
    when 'com.apple.developer.system-extension.install'
      capabilities << 'System Extension'
    when 'com.apple.developer.networking.custom-protocol'
      capabilities << 'Custom Network Protocol'
    end
  end

  capabilities
end

#enterprise?Boolean Also known as: inhouse?

Returns:

  • (Boolean)


112
113
114
115
116
# File 'lib/app_info/mobile_provision.rb', line 112

def enterprise?
  return false if platform == :macos # macOS no need adhoc

  !development? && !adhoc? && !appstore?
end

#entitlementsObject



65
66
67
# File 'lib/app_info/mobile_provision.rb', line 65

def entitlements
  mobileprovision.try(:[], 'Entitlements')
end

#expired_dateObject



61
62
63
# File 'lib/app_info/mobile_provision.rb', line 61

def expired_date
  mobileprovision.try(:[], 'ExpirationDate')
end

#mobileprovisionObject



203
204
205
206
207
208
209
210
211
212
# File 'lib/app_info/mobile_provision.rb', line 203

def mobileprovision
  return @mobileprovision = nil unless File.exist?(@path)

  data = File.read(@path)
  data = strip_plist_wrapper(data) unless bplist?(data)
  list = CFPropertyList::List.new(data: data).value
  @mobileprovision = CFPropertyList.native_types(list)
rescue CFFormatError
  @mobileprovision = nil
end

#nameObject



13
14
15
# File 'lib/app_info/mobile_provision.rb', line 13

def name
  mobileprovision.try(:[], 'Name')
end

#platformObject



37
38
39
# File 'lib/app_info/mobile_provision.rb', line 37

def platform
  platforms[0]
end

#platformsObject



28
29
30
31
32
33
34
35
# File 'lib/app_info/mobile_provision.rb', line 28

def platforms
  return unless platforms = mobileprovision.try(:[], 'Platform')

  platforms.map do |v|
    v = 'macOS' if v == 'OSX'
    v.downcase.to_sym
  end
end

#profile_nameObject



53
54
55
# File 'lib/app_info/mobile_provision.rb', line 53

def profile_name
  mobileprovision.try(:[], 'Name')
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


220
221
222
223
224
# File 'lib/app_info/mobile_provision.rb', line 220

def respond_to_missing?(method_name, *args)
  mobileprovision.key?(Util.format_key(method_name)) ||
    mobileprovision.respond_to?(method_name) ||
    super
end

#team_identifierObject



45
46
47
# File 'lib/app_info/mobile_provision.rb', line 45

def team_identifier
  mobileprovision.try(:[], 'TeamIdentifier')
end

#team_nameObject



49
50
51
# File 'lib/app_info/mobile_provision.rb', line 49

def team_name
  mobileprovision.try(:[], 'TeamName')
end

#typeObject



21
22
23
24
25
26
# File 'lib/app_info/mobile_provision.rb', line 21

def type
  return :development if development?
  return :adhoc if adhoc?
  return :appstore if appstore?
  return :enterprise if enterprise?
end