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

How to merge GoogleAnalytics and Firebase/Crashlytics GoogleService-info.plist?

如何合并 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?

终于成功了,

我们可以删除旧的 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/Analytics GoogleService-info.plist,我们可以放入适当的 dev/prod 文件夹,并根据配置在 Build Phase -> 运行 Script 中复制适当的一个。喜欢,

# 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