Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we have different Info.plist files for different environments such as Dev, Test, Staging, and Prod?

How can we have different Info.plist files for different environments such as Dev, Test, Staging, and Prod?

I have some settings and a separate Facebook app for each environments to ensure app analytics do not get biased by testers, etc. So really trying to avoid manually updating settings before building for each environment.

like image 481
Yas Tabasam Avatar asked Jan 18 '14 23:01

Yas Tabasam


People also ask

How do I create a different environment in Xcode?

Go to Build Settings and search for the app icon, and set the app icon in Asset Catalog App Icon Set Name, and here you can set resources for each configuration. This completes the process to create different environments and manage Xcode environment variables configuration.


2 Answers

Here is what you need to do to add environment specific plists.

  • Copy original ProjectName.Info.plist file to ProjectName_Dev.Info.plist, ProjectName_Test.Info.plist, and ProjectName_Staging.Info.plist and add them to the project.

  • Click on project name in the Project Navigator, select Target, then select Build Phases tab.

  • Type Info.plist in the search bar at top right to filter on Info.plist.

  • From under the Copy Bundle Resources, remove all plists except ProjectName.Info.plist

  • Now click on Editor -> Add Build Phase -> Add Run Script Build Phase menu option.

  • Finally, copy following shell script to the newly added Build Phase.

Make sure to replace ProjectName with your project name!

if [ "${CONFIGURATION}" == "Dev" ]; then
cp -r "${PROJECT_DIR}/ProjectName/ProjectName-Info_Dev.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/ProjectName-Info.plist"
echo "DEV plist copied"
elif [ "${CONFIGURATION}" == "Test" ]; then
cp -r "${PROJECT_DIR}/ProjectName/ProjectName-Info_Test.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/ProjectName-Info.plist"
echo "Beta plist copied"
elif [ "${CONFIGURATION}" == "Staging" ]; then
cp -r "${PROJECT_DIR}/ProjectName/ProjectName-Info_Staging.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/ProjectName-Info.plist"
echo "Beta plist copied"
elif [ "${CONFIGURATION}" == "Prod" ]; then
cp -r "${PROJECT_DIR}/ProjectName/ProjectName-Info_Prod.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/ProjectName-Info.plist"
echo "Beta plist copied"
fi

Or just:

cp -r "${PROJECT_DIR}/ProjectName/ProjectName-Info_${CONFIGURATION‌​}.plist" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/ProjectName-Info.‌​plist"

NOTE: I assume you already have created the build schemes with Dev, Test, Staging, and Production environment variables.

Got help from this article. http://www.dosomethinghere.com/2013/09/21/different-settings-app-entries-for-debug-vs-release-builds/

like image 102
Yas Tabasam Avatar answered Oct 28 '22 18:10

Yas Tabasam


You can also create separate xcconfig files for each target, use the project manager to assign each target the correct xcconfig file, and then just define a variable with the same name in each xcconfig and import that variable into your single plist. For example:

first xcconfig:

MY_VARIABLE = suchandsuch

second xcconfig:

MY_VARIABLE = thisandthat

And then in your plist, set a key with the value $(MY_VARIABLE)

Depends on what exactly you're doing. Xcconfig is nice because you can access the variables you set there in places like build settings in addition to plist.

like image 33
bgfriend0 Avatar answered Oct 28 '22 17:10

bgfriend0