Sobes.tech
Middle

How to change the app icon depending on the environment?

sobes.tech AI

Answer from AI

Depending on the environment (e.g., Dev, Staging, Prod), you can use:

  1. Creating separate targets for each environment.
  2. Using configuration files (.xcconfig).
  3. Adding custom keys in Info.plist.

Process:

  • Create duplicates of the main app target for each environment.
  • In the settings of each new target, change the Info.plist File or add the CFBundleIconFiles key and specify the icon file name.
  • In .xcconfig files for each environment, define a variable pointing to the respective Info.plist.
  • In the main target's Build Settings, set Info.plist File to ${INFO_PLIST_FILE} (where INFO_PLIST_FILE is a variable from .xcconfig).

Example .xcconfig for Dev:

// DEV.xcconfig
INFO_PLIST_FILE = Info_Dev.plist

Example Info_Dev.plist:

<!-- Info_Dev.plist -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	...
	<key>CFBundleIcons</key>
	<dict>
		<key>CFBundlePrimaryIcon</key>
		<dict>
			<key>CFBundleIconFiles</key>
			<array>
				<string>AppIconDev</string> // Asset name for Dev icon
			</array>
		</dict>
	</dict>
	...
</dict>
</plist>

An alternative approach without duplicating targets is to use build scripts that modify Info.plist depending on the current build configuration. However, using separate targets is more explicit and maintainable.

For managing icon assets, you can use separate Asset Catalogs for each target or configuration, or name icon sets uniquely (AppIconDev, AppIconStaging, AppIconProd) and specify the appropriate name in Info.plist.

How to change the app icon depending on the… - sobes.tech