I am using a build scheme for prod and one for staging (with 2 different bundle identifiers) and I am trying to use a separate GoogleService-Info.plist for each scheme. Is t
If the GoogleService-Info.plist
has a different name it will affect your analytics results. Firebase will warn you about this. https://github.com/firebase/firebase-ios-sdk/issues/230#issuecomment-327138180. For this reason, none of these runtime-solutions will provide the best analytics results.
There are two solutions that won't mess with Analytics.
Use a different target with each scheme and associate each version of GoogleService-Info.plist
with its own target. See Target Membership in the File inspector on the right hand side in Xcode. For further info See this question.
Use a build phase script to copy the correct version of GoogleService-Info.plist
into the build directory. I use a different bundle ID for staging and production. This enables me to have both versions of the app installed in parallel. It also means with the script below I can name my different GoogleService-Info.plist
files with the bundle ID. For example:
GoogleService-Info-com.example.app.plist
GoogleService-Info-com.example.app.staging.plist
PATH_TO_CONFIG=$SRCROOT/Config/GoogleService-Info-$PRODUCT_BUNDLE_IDENTIFIER.plist
FILENAME_IN_BUNDLE=GoogleService-Info.plist
BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo cp $PATH_TO_CONFIG "$BUILD_APP_DIR/$FILENAME_IN_BUNDLE"
cp $PATH_TO_CONFIG "$BUILD_APP_DIR/$FILENAME_IN_BUNDLE"
Note: You will have to change PATH_TO_CONFIG
to suit you setup.