Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A post install script for CocoaPods that changes the bundle identifier of all pods to the one specified.
post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == 'BREnterprise'
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'iPhone Distribution: The Carter Group LLC'
config.build_settings['PROVISIONING_PROFILE'] = '${BR_ENTERPRISE_PROVISIONING_PROFILE}'
end
end
end
# change bundle id of each pod to 'com.bottlerocketapps.*'
bundle_id = 'com.bottlerocketapps'
directory = installer.config.project_pods_root + 'Target Support Files/'
Dir.foreach(directory) do |path|
full_path = directory + path
if File.directory?(full_path)
info_plist_path = full_path + 'Info.plist'
if File.exist?(info_plist_path)
text = File.read(info_plist_path)
new_contents = text.gsub('org.cocoapods', bundle_id)
File.open(info_plist_path, "w") {|file| file.puts new_contents }
end
end
end
end
@sebastienbrault

This comment has been minimized.

Copy link

commented Jun 3, 2016

Thanks for sharing that. You saved my day and probably the two next one.

@RishabhTayal

This comment has been minimized.

Copy link

commented Dec 8, 2016

👍

@evermeer

This comment has been minimized.

Copy link

commented Feb 22, 2017

Extremely helpful. Since I wanted a different bundle_id per POD framework I changed the code to:

post_install do |installer|
    bundle_id = 'nl.evict.'
    directory = installer.config.project_pods_root + 'Target Support Files/'
    Dir.foreach(directory) do |path|
        full_path = directory + path
        if File.directory?(full_path)
            info_plist_path = full_path + 'Info.plist'
            if File.exist?(info_plist_path)                
                text = File.read(info_plist_path)
                new_contents = text.gsub('${PRODUCT_BUNDLE_IDENTIFIER}', bundle_id + path)
                File.open(info_plist_path, "w") {|file| file.puts new_contents }
            end
        end
    end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.