Abhinav
Abhinav

Reputation: 38152

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.

Upvotes: 8

Views: 5856

Answers (5)

Amitg2k12
Amitg2k12

Reputation: 3805

Simple approach would be,

1 -- Create the different target with the copy of existing target, 2 -- In the new target build phase elif [ ${CONFIGURATION} == "Release" ]; then cp -r ${PROJECT_DIR}/Settings/ReleaseHHAppStore/Settings.bundle ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app fi

this will allow you to make some more customisable setting if require

Upvotes: 0

Yevhen Dubinin
Yevhen Dubinin

Reputation: 4733

I have used @abhinav approach, but slightly modified it to fit my project's needs. We have two targets, BUT both are are used to build separate applications from.

steps

On the filesystem in project's directory create the folders structure:

<project_folder>/Settings/debug
<project_folder>/Settings/production

In the project create these Groups:

Settings
  debug
  production

Create a Settings.bundle, add it to debug group and save it to debug folder. (do not add it to any target)

Edit the .plistin a way that you'd like the most wide settings page would look like (usually, the Debug builds have more settings).

Copy the bundle from debug folder to production folder

Add Settings.bundle from production folder to production group in the project (do not add it to any target), so you have this structure

project group structure

Make sure none of Settings.bundles is added to any target

Remove setting items from production .plist you don't want to be shipped with App Store builds.

Add Run Script phase after Copy Bundle Resources phase

if [ "${CONFIGURATION}" = "Release" ]; then
cp -r ${PROJECT_DIR}/Settings/production/Settings.bundle "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app"
fi

if [ "${CONFIGURATION}" = "Debug" ]; then
cp -r ${PROJECT_DIR}/Settings/debug/Settings.bundle "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app"
fi

Note: I have two build schemes: Release and Debug. I have wrapped paths in quotation marks, because my target has the name with spaces.

Upvotes: 5

Greg
Greg

Reputation: 33650

I do something similar to @Abhinav, but instead of using a run script, I just use the Target Membership section of the File inspector to determine which target uses which Settings.bundle.

Settings Bundle Target Membership

Upvotes: 10

Abhinav
Abhinav

Reputation: 38152

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
fi

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

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

Upvotes: 11

CodaFi
CodaFi

Reputation: 43330

The only way to conditionally bundle items such as a settings bundle in different builds would be to duplicate your target. Simply add in the right bundle to the right target, and keep all the code the same. It's different, but it should work a lot better for you in the long run.

Upvotes: 1

Related Questions