Configuration dependent value in Info.plist file
Asked Answered
T

3

38

I have three configurations in my iOS project:

  1. Debug
  2. Adhoc
  3. Release

Now I want to change the name of the App as follows:

  1. MyAppDebug
  2. MyAppAdhoc
  3. MyApp (Note that this one does not have a suffix)

Is there a way I can easily achieve this in Xcode with some type of "compiler-if-else-macro-thing"?

Taphouse answered 23/1, 2012 at 12:19 Comment(1)
possible duplicate of Three slightly different Apps from one code baseTaphouse
D
64

Changing display name of app for respective configurations: one way to achieve this is by using the same info plist file that you have.

Part 1: create a user defined variable

  1. Click on target project file.
  2. Then at bottom right corner locate button "+" Add Build Setting.
  3. Click that button "Add Build Setting" and select "Add User-Defined Setting" enter name for New Setting as for ex: "BUNDLE_DISPLAY_NAME".
  4. Expand this new setting to see the configurations under it. Give the desired name to be displayed for each configuration. For ex: Debug -> MyAppDebug

Part 2: use it

  1. Select your appname-info.plist file.
  2. Locate key "Bundle Display Name" and value to it should be this new user defined variable ${BUNDLE_DISPLAY_NAME}

Then for appropriate configuration it will select name from BUNDLE_DISPLAY_NAME variable in build settings.

Dibs answered 9/8, 2013 at 21:5 Comment(3)
This is a great answer. Its a very valuable piece of information for anyone who's maintaining 2 versions of the app (Release/Production).Groveman
this is the best way to do this.Turino
Is there anyway to do this for boolean values? It didn't seem to work for me.Conveyancing
N
13

Also you can have two different info plist for different configurations which is different files and then from Build Settings > Info.plist File section you can change it. XCode 10.1

Novick answered 7/2, 2019 at 8:54 Comment(0)
E
3

Sure. First you have to create separate Info.plist file each configuration. Then in you Project's build settings find the line where Info.plist is placed, expand that line and choose separate Info.plist file for each configuration you have. Then you can enter desired name in corresponding field in each Info.plist file. That's it :)

Elephus answered 23/1, 2012 at 22:10 Comment(2)
Is it possible to do this, but not need to repeat all values for each plist? Or perhaps it's possible to have the value of a key in the main plist dynamically match one from a configuration plist?Bedrabble
Yes, create a user-defined build setting, then based on the configuration that you are building for, use that value.Cottonweed

© 2022 - 2024 — McMap. All rights reserved.