Class: Deliver::IpaFileAnalyser

Inherits:
Object
  • Object
show all
Defined in:
lib/deliver/ipa_file_analyser.rb

Class Method Summary collapse

Class Method Details

.fetch_app_identifier(path) ⇒ Object

Fetches the app identifier (e.g. com.facebook.Facebook) from the given ipa file.



5
6
7
8
9
# File 'lib/deliver/ipa_file_analyser.rb', line 5

def self.fetch_app_identifier(path)
  plist = IpaFileAnalyser.fetch_info_plist_file(path)
  return plist['CFBundleIdentifier'] if plist
  return nil
end

.fetch_app_version(path) ⇒ Object

Fetches the app version from the given ipa file.



12
13
14
15
16
# File 'lib/deliver/ipa_file_analyser.rb', line 12

def self.fetch_app_version(path)
  plist = IpaFileAnalyser.fetch_info_plist_file(path)
  return plist['CFBundleShortVersionString'] if plist
  return nil
end

.fetch_info_plist_file(path) ⇒ Object



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
# File 'lib/deliver/ipa_file_analyser.rb', line 18

def self.fetch_info_plist_file(path)
  Zip::File.open(path) do |zipfile|
    zipfile.each do |file|
      if file.name.include?'.plist' and not ['.bundle', '.framework'].any? { |a| file.name.include?a }
        # We can not be completely sure, that's the correct plist file, so we have to try
        begin
          # The XML file has to be properly unpacked first
          tmp_path = "/tmp/deploytmp.plist"
          File.write(tmp_path, zipfile.read(file))
          system("plutil -convert xml1 #{tmp_path}")
          result = Plist::parse_xml(tmp_path)
          File.delete(tmp_path)

          if result['CFBundleIdentifier'] or result['CFBundleVersion']
            return result
          end
        rescue
          # We don't really care, look for another XML file
        end
      end
    end
  end

  nil
end