Skip to content

Instantly share code, notes, and snippets.

@joshdholtz
Created September 20, 2017 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshdholtz/204b7083a59436ff02df198629bd9ca1 to your computer and use it in GitHub Desktop.
Save joshdholtz/204b7083a59436ff02df198629bd9ca1 to your computer and use it in GitHub Desktop.
Add/configure new entitlements to project
def ios_add_push_entitlements(project_path)
entitlements_template_name = "app-template.entitlements"
entitlements_template_path = File.absolute_path entitlements_template_name
entitlements_template = File.read(entitlements_template_path)
# Replacing entitlement template with debug info
debug_file_name = "app-debug.entitlements"
debug_file = File.new(, "w")
debug_file.puts entitlements_template
.gsub("REPLACE_ENVIRONMENT", "debug")
.gsub("REPLACE_BUNDLE_ID", "com.joshiscool.app")
debug_file.close
# Replacing entitlement template with release info
release_file_name = "app-release.entitlements"
release_file = File.new(, "w")
release_file.puts entitlements_template
.gsub("REPLACE_ENVIRONMENT", "debug")
.gsub("REPLACE_BUNDLE_ID", "com.joshiscool.app")
release_file.close
# Opening project
require 'xcodeproj'
xcproj = Xcodeproj::Project.open(project_path)
# Adding these new entitlement files to the project (if they don't exist already)
file_names = xcproj.files.map(&:name)
xcproj.new_file(debug_file_name) unless file_names.include? debug_file_name
xcproj.new_file(release_file_name) unless file_names.include? release_file_name
# Setting the entitlements per target
xcproj.targets.each do |target|
target.build_configurations.each do |config|
entitlement = config.name == "Release" ? release_file_name : debug_file_name
config.build_settings['CODE_SIGN_ENTITLEMENTS'] = entitlement
end
end
xcproj.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment