Skip to content

Instantly share code, notes, and snippets.

@pdsarin

pdsarin/profile_uuid.rb

Last active Aug 15, 2020
Embed
What would you like to do?
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