loading...
Cover image for How to have Debug and Release Firebase environments in an iOS project
The Agile Monkeys

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

jfsagasti profile image Juan Sagasti ・2 min read

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.

  1. Create your Development and Production projects in Firebase and download both GoogleService-info.plist.
  2. 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. Xcode
  3. Add a new build script phase. If you have a Crashlytics script, add it before it. I've called it Firebase script selection: Build Phases
  4. Add this code to the script you have added:
INFO_PLIST=GoogleService-Info.plist

DEVELOPMENT_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 ] ; then
    echo "Development GoogleService-Info.plist not found."
    exit 1
fi

echo "Checking ${INFO_PLIST} in ${RELEASE_INFO_PLIST}"
if [ ! -f $RELEASE_INFO_PLIST ] ; then
    echo "Release GoogleService-Info.plist not found."
    exit 1
fi

PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo "Copying ${INFO_PLIST} to final destination: ${PLIST_DESTINATION}"

if [ "${CONFIGURATION}" == "Release" ] ; then
    echo "Copied ${RELEASE_INFO_PLIST}."
    cp "${RELEASE_INFO_PLIST}" "${PLIST_DESTINATION}"
else
    echo "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:

Scheme

Schema configuration

Posted on by:

jfsagasti profile

Juan Sagasti

@jfsagasti

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

The Agile Monkeys

We create serverless technology

Discussion

markdown guide