Skip to content

Instantly share code, notes, and snippets.

@daltonclaybrook
Last active January 21, 2022 22:36
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save daltonclaybrook/e109033af85e6efd6972 to your computer and use it in GitHub Desktop.
Save daltonclaybrook/e109033af85e6efd6972 to your computer and use it in GitHub Desktop.
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
@RishabhTayal
Copy link

👍

@evermeer
Copy link

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

@peter-mach
Copy link

Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment