Skip to content

Instantly share code, notes, and snippets.

@pdsarin
Last active August 15, 2020 05:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdsarin/5377836 to your computer and use it in GitHub Desktop.
Save pdsarin/5377836 to your computer and use it in GitHub Desktop.
Ruby function to extract a provisioning profile UUID from a .mobileprovision file and to dynamically generate an xcconfig file
# Extract a profile UUID from a mobileprovision file.
# Makes it easier to programatically build against a particular profile
# without having to install it manually.
require 'nokogiri'
def profile_uuid(provisioning_profile_path)
profile_contents = File.open(provisioning_profile_path).read
profile_contents = profile_contents.slice(profile_contents.index('<?'), profile_contents.length)
doc = Nokogiri.XML(profile_contents)
return doc.xpath('//key[text()="UUID"]')[0].next_element.text
end
# Generate an xcconfig file dynamically
require 'tempfile'
def xcconfig_file(config)
file = Tempfile.new('xcconfig')
if config[:provisioning_profile]
file.write("PROVISIONING_PROFILE = #{profile_uuid(config[:provisioning_profile])}\n")
end
config[:xcconfig].each do |key, value|
file.write("#{key} = #{value}\n")
end
file.close
return file.path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment