【问题标题】:How to merge GoogleAnalytics and Firebase/Crashlytics GoogleService-info.plist?如何合并 GoogleAnalytics 和 Firebase/Crashlytics GoogleService-info.plist?
【发布时间】:2021-02-18 20:53:28
【问题描述】:

如何合并 GoogleAnalytics 和 Firebase/Crashlytics GoogleService-info.plist?

在一个 iOS 项目中,我一直在使用 GoogleAnalytics 和 Fabric。现在我正在尝试将 Fabric 迁移到 Firebase/Crashlytics。 GoogleAnalytics 一直在使用 GoogleService-info.plist,而且 Firebase 需要将 GoogleService-info.plist 发送到support。虽然我使用的是同一个帐户。两个 GOOGLE_APP_ID 在 GoogleService-info.plist 中都显示不同。如何同时使用 GoogleAnalitics 和 Firebase/Crashlytics 版本?

【问题讨论】:

    标签: ios firebase google-analytics google-fabric firebase-crash-reporting


    【解决方案1】:

    终于成功了,

    我们可以删除旧的 GoogleAnalytics GoogleService-info.plist 并像下面这样动态设置 GA 配置 (more detail),

    [GAI sharedInstance].trackUncaughtExceptions = YES;
    [[GAI sharedInstance].logger setLogLevel:kGAILogLevelVerbose];
    [GAI sharedInstance].dispatchInterval = 20;
    id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXXXXXX-Y"];
    

    然后对于Firebase/AnalyticsGoogleService-info.plist,我们可以放入适当的dev/prod文件夹,并在Build Phase -> Run Script based onconfigurations中复制适当的文件夹。喜欢,

    # Name of the resource we're selectively copying
    GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
    
    # Get references to dev and prod versions of the GoogleService-Info.plist
    # NOTE: These should only live on the file system and should NOT be part of the target (since we'll be adding them to the target manually)
    GOOGLESERVICE_INFO_DEV=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Dev/${GOOGLESERVICE_INFO_PLIST}
    GOOGLESERVICE_INFO_PROD=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Prod/${GOOGLESERVICE_INFO_PLIST}
    
    # Make sure the dev version of GoogleService-Info.plist exists
    echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_DEV}"
    if [ ! -f $GOOGLESERVICE_INFO_DEV ]
    then
        echo "No Development GoogleService-Info.plist found. Please ensure it's in the proper directory."
        exit 1
    fi
    
    # Make sure the prod version of GoogleService-Info.plist exists
    echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_PROD}"
    if [ ! -f $GOOGLESERVICE_INFO_PROD ]
    then
        echo "No Production GoogleService-Info.plist found. Please ensure it's in the proper directory."
        exit 1
    fi
    
    # Get a reference to the destination location for the GoogleService-Info.plist
    PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
    echo "Will copy ${GOOGLESERVICE_INFO_PLIST} to final destination: ${PLIST_DESTINATION}"
    
    # Copy over the prod GoogleService-Info.plist for Release builds
    if [ "${CONFIGURATION}" == "Release" ]
    then
        echo "Using ${GOOGLESERVICE_INFO_PROD}"
        cp "${GOOGLESERVICE_INFO_PROD}" "${PLIST_DESTINATION}"
    else
        echo "Using ${GOOGLESERVICE_INFO_DEV}"
        cp "${GOOGLESERVICE_INFO_DEV}" "${PLIST_DESTINATION}"
    fi
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-11
      • 2020-12-17
      • 1970-01-01
      • 2016-03-21
      • 2016-11-27
      • 1970-01-01
      • 2017-04-23
      • 2022-12-14
      相关资源
      最近更新 更多