Class: AppInfo::InfoPlist

Inherits:
File
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/app_info/info_plist.rb

Overview

iOS Info.plist parser

Constant Summary collapse

ICON_KEYS =

Icon Key

{
  Device::Apple::IPHONE => ['CFBundleIcons'],
  Device::Apple::IPAD => ['CFBundleIcons~ipad'],
  Device::Apple::UNIVERSAL => ['CFBundleIcons', 'CFBundleIcons~ipad'],
  Device::Apple::MACOS => %w[CFBundleIconFile CFBundleIconName]
}.freeze

Instance Attribute Summary

Attributes inherited from File

#file, #logger

Instance Method Summary collapse

Methods inherited from File

#format, #initialize, #not_implemented_error!, #size

Constructor Details

This class inherits a constructor from AppInfo::File

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



193
194
195
196
197
# File 'lib/app_info/info_plist.rb', line 193

def method_missing(method_name, *args, &block)
  info.try(:[], method_name.to_s.ai_camelcase) ||
    info.send(method_name) ||
    super
end

Instance Method Details

#[](key) ⇒ String?

Returns:

  • (String, nil)


185
186
187
# File 'lib/app_info/info_plist.rb', line 185

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

#appletv?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/app_info/info_plist.rb', line 135

def appletv?
  device == Device::Apple::APPLETV
end

#background_modesArray<String>

Services provided by an app that require it to run in the background

Returns:

  • (Array<String>)


180
181
182
# File 'lib/app_info/info_plist.rb', line 180

def background_modes
  info.try(:[], 'UIBackgroundModes') || []
end

#build_versionString?

Returns:

  • (String, nil)


62
63
64
# File 'lib/app_info/info_plist.rb', line 62

def build_version
  info.try(:[], 'CFBundleVersion')
end

#bundle_nameString?

Returns:

  • (String, nil)


88
89
90
# File 'lib/app_info/info_plist.rb', line 88

def bundle_name
  info.try(:[], 'CFBundleName')
end

#deviceSymbol

Returns Device.

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/app_info/info_plist.rb', line 38

def device
  if device_family == [1]
    Device::Apple::IPHONE
  elsif device_family == [2]
    Device::Apple::IPAD
  elsif device_family == [1, 2]
    Device::Apple::UNIVERSAL
  elsif device_family == [3]
    Device::Apple::APPLETV
  elsif device_family == [6]
    Device::Apple::APPMACOSLETV
  elsif !info.try(:[], 'DTSDKName').nil? || !info.try(:[], 'DTManufacturerName').nil?
    Device::Apple::MACOS
  else
    raise NotImplementedError, "Unkonwn device: #{device_family}"
  end
end

#device_familyArray<String>

Returns:

  • (Array<String>)


140
141
142
# File 'lib/app_info/info_plist.rb', line 140

def device_family
  info.try(:[], 'UIDeviceFamily') || []
end

#display_nameString?

Returns:

  • (String, nil)


83
84
85
# File 'lib/app_info/info_plist.rb', line 83

def display_name
  info.try(:[], 'CFBundleDisplayName')
end

#iconsArray<String>

Returns:

  • (Array<String>)


110
111
112
# File 'lib/app_info/info_plist.rb', line 110

def icons
  @icons ||= ICON_KEYS[device]
end

#identifierString? Also known as: bundle_id

Returns:

  • (String, nil)


72
73
74
# File 'lib/app_info/info_plist.rb', line 72

def identifier
  info.try(:[], 'CFBundleIdentifier')
end

#ipad?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/app_info/info_plist.rb', line 120

def ipad?
  device == Device::Apple::IPAD
end

#iphone?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/app_info/info_plist.rb', line 115

def iphone?
  device == Device::Apple::IPHONE
end

#macos?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/app_info/info_plist.rb', line 130

def macos?
  device == Device::Apple::MACOS
end

#manufacturerSymbol

Returns Manufacturer.

Returns:



21
22
23
# File 'lib/app_info/info_plist.rb', line 21

def manufacturer
  Manufacturer::APPLE
end

#min_os_versionString?

Returns:

  • (String, nil)


93
94
95
# File 'lib/app_info/info_plist.rb', line 93

def min_os_version
  min_sdk_version || min_system_version
end

#min_sdk_versionString?

Extract the Minimum OS Version from the Info.plist (iOS Only)

Returns:

  • (String, nil)


99
100
101
# File 'lib/app_info/info_plist.rb', line 99

def min_sdk_version
  info.try(:[], 'MinimumOSVersion')
end

#min_system_versionString?

Extract the Minimum OS Version from the Info.plist (macOS Only)

Returns:

  • (String, nil)


105
106
107
# File 'lib/app_info/info_plist.rb', line 105

def min_system_version
  info.try(:[], 'LSMinimumSystemVersion')
end

#nameString?

Returns:

  • (String, nil)


78
79
80
# File 'lib/app_info/info_plist.rb', line 78

def name
  display_name || bundle_name
end

#platformSymbol

Returns Platform.

Returns:



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

def platform
  case device
  when Device::Apple::MACOS
    Platform::MACOS
  when Device::Apple::IPHONE, Device::Apple::IPAD, Device::Apple::UNIVERSAL
    Platform::IOS
  when Device::Apple::APPLETV
    Platform::APPLETV
  end
end

#query_schemesArray<String>

Specifies the URL schemes you want the app to be able to use

Returns:

  • (Array<String>)


173
174
175
# File 'lib/app_info/info_plist.rb', line 173

def query_schemes
  info.try(:[], 'LSApplicationQueriesSchemes') || []
end

#release_typeString

Returns:

  • (String)


145
146
147
148
149
150
151
# File 'lib/app_info/info_plist.rb', line 145

def release_type
  if stored?
    'Store'
  else
    build_type
  end
end

#release_versionString?

Returns:

  • (String, nil)


67
68
69
# File 'lib/app_info/info_plist.rb', line 67

def release_version
  info.try(:[], 'CFBundleShortVersionString')
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


199
200
201
202
203
# File 'lib/app_info/info_plist.rb', line 199

def respond_to_missing?(method_name, *args)
  info.key?(method_name.to_s.ai_camelcase) ||
    info.respond_to?(method_name) ||
    super
end

#to_hObject

See Also:

  • CFPropertyList#to_h


191
# File 'lib/app_info/info_plist.rb', line 191

def_delegators :info, :to_h

#universal?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/app_info/info_plist.rb', line 125

def universal?
  device == Device::Apple::UNIVERSAL
end

#url_schemesArray<String>

A list of URL schemes (http, ftp, and so on) supported by the app.

Returns:

  • (Array<String>)


156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/app_info/info_plist.rb', line 156

def url_schemes
  url_types = info.try(:[], 'CFBundleURLTypes')
  return [] unless url_types

  url_types.each_with_object([]) do |url_type, obj|
    data = {
      role: url_type['CFBundleTypeRole'],
      name: url_type['CFBundleURLName'],
      schemes: url_type['CFBundleURLSchemes']
    }
    obj << data
  end
end

#versionString?

Returns:

  • (String, nil)


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

def version
  release_version || build_version
end