xcode change code signing identity by ruby gem xcodeproj

1.2k Views Asked by At

I'm totally new to Ruby but managed to change the project based code signing identity and provisioning profile in xcode like so:

#!/usr/bin/env ruby

require 'xcodeproj'

xcproj = Xcodeproj::Project.open("MyProject.xcodeproj")

xcproj.build_configurations.each do |item|
    item.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = "iOS Development: xxxxxx xxxx (xxxxxxxxx)"
end

xcproj.build_configurations.each do |item|
    item.build_settings['PROVISIONING_PROFILE[sdk=iphoneos*]'] = "628352b1-9b78-xxxx-xxxx-xxxxxxxxx"
end

xcproj.save

My problem is the target based code signing identity and provisioning profile will override the project based one. But I can't find a method to directly set the target based one. Hope someone can help here. Thanks

2

There are 2 best solutions below

0
On

You can use the xcodebuild tool to change the code sign identity and provisioning profile, instead of directly editing the project (.xcodeproj) file:

xcodebuild -sdk <iphoneos> -target <target_name> -configuration <Debug> CODE_SIGN_IDENTITY="iOS Development: xxxxxx xxxx (xxxxxxxxx)" PROVISIONING_PROFILE="628352b1-9b78-xxxx-xxxx-xxxxxxxxx"

0
On

You can access the targets of the project by calling native_targets on project, like so:

#!/usr/bin/env ruby

require 'xcodeproj'

xcproj = Xcodeproj::Project.open("MyProject.xcodeproj")
target = xcproj.native_targets.detect { |target| target.name == "MyTarget" }

target.build_configurations.each do |item|
  item.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = "iOS Development: xxxxxx xxxx (xxxxxxxxx)"
end

target.build_configurations.each do |item|
  item.build_settings['PROVISIONING_PROFILE[sdk=iphoneos*]'] = "628352b1-9b78-xxxx-xxxx-xxxxxxxxx"
end

xcproj.save