Last active
August 15, 2020 05:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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