Use different GoogleService-Info.plist for different build schemes

后端 未结 17 726
梦毁少年i
梦毁少年i 2020-12-07 07:49

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

17条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 08:31

    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.

    1. 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.

    2. 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

    Build Phase Script

    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.

提交回复
热议问题