Class: AppPermissionStatistics::InfoPlist

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

Overview

iOS Info.plist parser

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ InfoPlist

Returns a new instance of InfoPlist.



20
21
22
# File 'lib/app_permission_statistics/info_plist.rb', line 20

def initialize(file)
    @file = file
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



181
182
183
184
185
# File 'lib/app_permission_statistics/info_plist.rb', line 181

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) ⇒ Object



175
176
177
# File 'lib/app_permission_statistics/info_plist.rb', line 175

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

#backgroundModesObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/app_permission_statistics/info_plist.rb', line 38

def backgroundModes
    value = info.try(:[], 'UIBackgroundModes')
    if !value.nil? 
        return   {
            "BackgroundModes" => {
                "UIBackgroundModes" => value
            }
        }                
    end
end

#build_versionObject



112
113
114
# File 'lib/app_permission_statistics/info_plist.rb', line 112

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

#bundle_nameObject



133
134
135
# File 'lib/app_permission_statistics/info_plist.rb', line 133

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

#device_familyObject



171
172
173
# File 'lib/app_permission_statistics/info_plist.rb', line 171

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

#device_typeObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/app_permission_statistics/info_plist.rb', line 95

def device_type
    device_family = info.try(:[], 'UIDeviceFamily')
    if device_family == [1]
        Device::IPHONE
    elsif device_family == [2]
        Device::IPAD
    elsif device_family == [1, 2]
        Device::UNIVERSAL
    elsif !info.try(:[], 'DTSDKName').nil? || !info.try(:[], 'DTPlatformName').nil?
        Device::MACOS
    end
end

#display_nameObject



129
130
131
# File 'lib/app_permission_statistics/info_plist.rb', line 129

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

#enabled_capabilitiesObject

Extract the capabilities from the Info.plist mercury.tencent.com/introduction/show?item=ios



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/app_permission_statistics/info_plist.rb', line 53

def enabled_capabilities 
    capabilities = Hash.new
    info.each do |key, value|
        case key
        when 'UIRequiredDeviceCapabilities' 
            capabilities['RequiredDeviceCapabilities']  = {
                key => value
            }
        when 'UIFileSharingEnabled' 
            capabilities['FileSharingEnabled' ] = {
                key => value
            }
        when 'CADisableMinimumFrameDurationOnPhone' 
            capabilities['DisableMinimumFrameDurationOnPhone'] = {
                key => value
            }
        when 'GCSupportedGameControllers' 
            capabilities['GameControllers'] = {
                key => value
            }
        when 'GCSupportsControllerUserInteraction' 
            capabilities['SupportsControllerUserInteraction' ] = {
                key => value
            }
        when 'MKDirectionsApplicationSupportedModes' 
            capabilities['Maps'] = {
                key => value
            }
        when 'NSAppTransportSecurity' 
            capabilities['AppTransportSecurity'] = {
                key => value
            }
        when 'CFBundleDocumentTypes' 
            capabilities['BundleDocumentTypes'] = {
                key => value
            }
        end 
    end   
    capabilities         
end

#identifierObject Also known as: bundle_id



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

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

#ipad?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/app_permission_statistics/info_plist.rb', line 159

def ipad?
    device_type == Device::IPAD
end

#iphone?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/app_permission_statistics/info_plist.rb', line 155

def iphone?
    device_type == Device::IPHONE
end

#macos?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/app_permission_statistics/info_plist.rb', line 167

def macos?
    device_type == Device::MACOS
end

#min_os_versionObject



137
138
139
# File 'lib/app_permission_statistics/info_plist.rb', line 137

def min_os_version
    min_sdk_version || min_system_version
end

#min_sdk_versionObject

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



144
145
146
# File 'lib/app_permission_statistics/info_plist.rb', line 144

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

#min_system_versionObject

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



151
152
153
# File 'lib/app_permission_statistics/info_plist.rb', line 151

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

#nameObject



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

def name
    display_name || bundle_name
end

#permis_usagedescriptionObject



28
29
30
31
32
33
34
35
36
# File 'lib/app_permission_statistics/info_plist.rb', line 28

def permis_usagedescription
    desc = Hash.new
    info.each do |key, value|
        if key.include?("UsageDescription")
            desc[key] = value
        end 
    end
    desc
end

#release_versionObject



116
117
118
# File 'lib/app_permission_statistics/info_plist.rb', line 116

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

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


187
188
189
190
191
# File 'lib/app_permission_statistics/info_plist.rb', line 187

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

#universal?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/app_permission_statistics/info_plist.rb', line 163

def universal?
    device_type == Device::UNIVERSAL
end

#versionObject



108
109
110
# File 'lib/app_permission_statistics/info_plist.rb', line 108

def version
    release_version || build_version
end