How to have Debug and Release Firebase environments in an iOS project

Juan Sagasti
The Agile Monkeys’ Journey
2 min readMay 14, 2020

We should be using a debug environment when developing unreleased features to the public so we don’t affect the environment where your real users are (avoids risks), plus we don’t clutter it with testing data.

This is kind of obvious nowadays. But let’s see how to do it with a Firebase project in Xcode.

  • Create your Development and Production projects in Firebase and download both GoogleService-info.plist.
  • Add a Firebase directory in your project, with Development and Release subfolders. Add the plist of each environment to its respective folder, but unchecking the add to the target option because we are going to add the correct file to it during the build phase.
  • Add a new build script phase. If you have a Crashlytics script, add it before it. I’ve called it Firebase script selection:
  • Add this code to the script you have added:
INFO_PLIST=GoogleService-Info.plistDEVELOPMENT_INFO_PLIST=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Development/${INFO_PLIST}RELEASE_INFO_PLIST=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Release/${INFO_PLIST}echo “Checking ${INFO_PLIST} in ${DEVELOPMENT_INFO_PLIST}”if [ ! -f $DEVELOPMENT_INFO_PLIST ] ; thenecho “Development GoogleService-Info.plist not found.”exit 1fiecho “Checking ${INFO_PLIST} in ${RELEASE_INFO_PLIST}”if [ ! -f $RELEASE_INFO_PLIST ] ; thenecho “Release GoogleService-Info.plist not found.”exit 1fiPLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.appecho “Copying ${INFO_PLIST} to final destination: ${PLIST_DESTINATION}”if [ “${CONFIGURATION}” == “Release” ] ; thenecho “Copied ${RELEASE_INFO_PLIST}.”cp “${RELEASE_INFO_PLIST}” “${PLIST_DESTINATION}”elseecho “Copied ${DEVELOPMENT_INFO_PLIST}.”cp “${DEVELOPMENT_INFO_PLIST}” “${PLIST_DESTINATION}”fi

And that’s it! Now you will be using the development environment when developing/testing your app and the release one when archiving the project.

If you want to test your release environment when developing too, you can just create a new compilation scheme for that:

Originally published at https://dev.to on May 14, 2020.

--

--

Juan Sagasti
The Agile Monkeys’ Journey

Software Engineer  & Co-founder at The Agile Monkeys 🐒