Use User-Defined build settings in custom .plist file

后端 未结 4 1621
感动是毒
感动是毒 2020-12-24 14:22

I have different build configurations (Debug, Stage, Prod) defined for my app and I use User-Defined build settings:

to set up Facebook log

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 14:48

    1. Create a new folder (for example: GoogleServiceInfoPlists).

    2. Copy there all .plist files for each Configuration

    for example:

    GoogleService-Info-Debug.plist, 
    GoogleService-Info-Alpha.plist,
    GoogleService-Info-Beta.plist,
    GoogleService-Info-Release.plist
    
    1. Add new Run Script Phase at last (Xcode: Target -> Build Phases -> "+" button).

    2. Use script below to copy .plist file for given environment to the build directory.

    script:

    RESOURCE_PATH=${SRCROOT}/${PRODUCT_NAME}/GoogleServiceInfoPlists/GoogleService-Info-$CONFIGURATION.plist
    
    BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
    
    echo "Copying ${RESOURCE_PATH} to ${BUILD_APP_DIR}"
    cp "${RESOURCE_PATH}" "${BUILD_APP_DIR}/GoogleService-Info.plist"
    

    PS: You do not need to add the file to project. Just create a new folder in the main directory.

提交回复
热议问题