In new Firebase, how to use multiple config file in xcode?

后端 未结 9 1467
被撕碎了的回忆
被撕碎了的回忆 2021-01-30 09:14

Hey I am playing with the new firebase iOS SDK, in my project, I have only one target, I created two configurations, Debug and Release, with different bundler identifier, but se

9条回答
  •  迷失自我
    2021-01-30 09:38

    I've implemented something similar, as I've had two schemes for a single target that have different bundle identifiers. In my examples below, I have two different schemes, one for UAT and one for PROD.

    Create the two GoogleService-Info.json files, and put them into your project directory (not Xcode project) in different folders, e.g.

    ROOT/config/UAT/GoogleService-Info.json
    ROOT/config/PROD/GoogleService-Info.json
    

    Then add the files to your Xcode project like so:

    Now you need to add a Run Script in your Build Phases. This will need to be added before the Compile Sources stage:

    This Run Script takes the appropriately located json file and duplicates it into the build app directory, meaning Firebase/Google will identify it identically to how it would identify the file in a single identifier setup.

    isUAT=`expr "$GCC_PREPROCESSOR_DEFINITIONS" : ".*UAT=\([0-9]*\)"`
    
    RESOURCE_PATH=${SRCROOT}/${PRODUCT_NAME}/config/PROD
    
    if [ $isUAT = 1 ]; then
        RESOURCE_PATH=${SRCROOT}/${PRODUCT_NAME}/config/UAT
    fi
    
    BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
    
    echo "Copying all files under ${RESOURCE_PATH} to ${BUILD_APP_DIR}"
    cp -v "${RESOURCE_PATH}/"* "${BUILD_APP_DIR}/"
    

    I would estimate you can use this same logic for Google Analytics as well, which uses a similar json config file setup.

提交回复
热议问题