Abhinav Abhinav - 1 year ago 150
iOS Question

Defining Settings bundle based on the build configuration

I have defined my Root.plist inside Setting bundle which appears in the device settings. Now, I want it to display different options based on the kind of environment I build the project on.

I have defined a TEST and PROD schemes (different build configuration) in XCode and I want Root.plist to be defined differently for these build configuration. How can this be done?

Can we have 2 plists defined and link them with different build configuration or can we modify the root.plist at the compile time based on the build configuration or scheme chosen.

Please advise.

Answer Source

I have worked it out this way:

1) Add 2 settings bundle (one for test and one for prod) to the project and add them to the target.

2) Add a Run script on the Runner target to selectively copy the required Settings bundle into the build file.

if [IS_PRODUCTION]; then
cp -r ${PROJECT_DIR}/Settings/Prod/Settings.bundle ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app

if [IS_TEST]; then
cp -r ${PROJECT_DIR}/Settings/Test/Settings.bundle ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app

3) Once done, just run on different schemes to see the desired results.