Last active
November 16, 2018 04:16
-
-
Save thelvis4/253a2cdea8360da519b2a025c5d8fbac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/ruby | |
require 'xcodeproj' | |
# ============================================ | |
# !!! I've released a ruby gem that does the same thing, but better. | |
# You can install it by running `gem install xcprovisioner` or | |
# `sudo gem install xcprovisioner` if it asks for sudo rights. | |
# | |
# For more info: https://github.com/thelvis4/XCProvisioner | |
# ============================================ | |
# Usage: | |
# ruby select_xcode_signing_method.rb -p <path/to/xcode_project> -t <Target> -m ['Automatic' | 'Manual'] | |
class Options | |
attr_accessor :path, :target, :method | |
def initialize(args) | |
@path = args[:path] || Dir.glob("*.xcodeproj").first | |
@target = args[:target] | |
@method = args[:method] | |
end | |
end | |
def parse_args | |
options_hash = {} | |
args = ARGV | |
args.each_with_index do |arg, index| | |
case arg | |
when '--project_path', '-p' | |
path = args[index + 1] | |
unless File.exist?(path) | |
abort('There is no file at specified path.') | |
end | |
options_hash[:path] = path | |
when '--target', '-t' | |
options_hash[:target] = args[index + 1] | |
when '--signing_method', '-m' | |
method = args[index + 1] | |
unless ['Automatic', 'Manual'].include?(method) | |
abort("'Invalid signing method specified. Please use either 'Automatic' or 'Manual'") | |
end | |
options_hash[:method] = method | |
end | |
end | |
options_hash | |
end | |
options = Options.new parse_args | |
project = Xcodeproj::Project.open(options.path) | |
target_id = project.targets.select {|target| target.name == options.target }.first.uuid | |
attributes = project.root_object.attributes['TargetAttributes'] | |
target_attributes = attributes[target_id] | |
target_attributes['ProvisioningStyle'] = options.method | |
project.save | |
puts "Code signing was set to '#{options.method}'." |
@nguyenhoangmisfit Sorry for responding so late. Hope it's still relevant.
- If you know the UUID of the target you want to add to
TargetAttributes
project = Xcodeproj::Project.open(options.path)
target_id = project.targets.select {|target| target.name == options.target }.first.uuid
Something like this will do the trick:
target_attributes = { target_id => { 'CreatedOnToolsVersion' => '9.0', 'ProvisioningStyle' => 'Automatic' } }
project.root_object.attributes['TargetAttributes'] = target_attributes
project.save
- If you want to set the attributes for all the targets, you can do something like this:
# create target attributes dictionary
attributes = { 'CreatedOnToolsVersion' => '9.0', 'ProvisioningStyle' => 'Automatic' }
target_attributes = {}
project.targets.each { |target| target_attributes[target.uuid] = attributes }
# assign it to project
project.root_object.attributes['TargetAttributes'] = target_attributes
# save the project
project.save
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a question: In case, if in xcodeproj file we haven't TargetAttributes session yet, how can we use xcodeproj to generate TargetAttributes for targets. I'm finding a solution to automatically set Automatic for ProvisioniningStyle of Pods target.
Thanks.