Skip to content

Instantly share code, notes, and snippets.

@drunknbass
Created June 17, 2016 04:05
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save drunknbass/49c1abc13c1df1f6b65710afb03c330f to your computer and use it in GitHub Desktop.
Save drunknbass/49c1abc13c1df1f6b65710afb03c330f to your computer and use it in GitHub Desktop.
Firebase stage + Prod config
STEP 1.
Add a flag in the "Other Swift Flags" like -DENVConfigStaging to a debug target.
Now when you build this target you have a debug flag set, otherwise assume production.
STEP 2.
Add the staging and production GoogleService-Info.plist(s)
STEP 3.
Add a build phase script to look for the build flag and copy the appropriate GoogleService-Info.plist to the built .app before codesigning it
Doing this allows you to create a class like EnvConfig.swift to define env specific stuff
You can do the same thing with GCC preprocessor flags, etc.. if you don't swift
CURRENT_DIR=`pwd -P`
SOURCE_DIR="$CURRENT_DIR/PROJECTNAME/"
if [[ $OTHER_SWIFT_FLAGS == *"-DENVConfigStaging"* ]]
then
cp "$SOURCE_DIR/GoogleService-Info.plist.staging" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist"
else
cp "$SOURCE_DIR/GoogleService-Info.plist.production" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist"
fi
import Foundation
@objc(EnvConfig)
class EnvConfig: NSObject {
#if ENVConfigStaging
class var isProduction:Bool {
return false
}
#else
class var isProduction:Bool {
return true
}
#endif
}
@lavenj
Copy link

lavenj commented Jun 30, 2016

Love this gist! FYI you can use ${UNLOCALIZED_RESOURCES_FOLDER_PATH} instead of ${PRODUCT_NAME}.app in the .sh

@warpling
Copy link

Thanks for this!
Couple tweaks that could help anyone else stumbling across this:

Why not use the dynamic project name here too:

SOURCE_DIR="$CURRENT_DIR/${PROJECT_NAME}/"

Standard Debug/Release configs:

if [ "${CONFIGURATION}" = "Debug" ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment