iOS从Crashlytics迁移到FirebaseCrashlytics

时间:2020-06-17 10:14:32

标签: ios objective-c firebase crashlytics

我以前曾将项目从Fabric迁移到Firebase,现在正试图从Crashlytics迁移到FirebaseCrashlytics,但是遇到了问题。我一直跟随upgrade guide,但无济于事。

我的项目有多个方案,确切地说是4个,每个方案都有不同的Bundle ID,因此也有不同的GoogleService-Info.plist。我已经在Crashlytics运行脚本阶段解决了该问题,它看起来如下:

GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist

GOOGLESERVICE_INFO_APP_STORE=${PROJECT_DIR}/${TARGET_NAME}/Application/Firebase/AppStore/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_PRODUCTION=${PROJECT_DIR}/${TARGET_NAME}/Application/Firebase/Production/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_BETA=${PROJECT_DIR}/${TARGET_NAME}/Application/Firebase/Beta/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_STAGING=${PROJECT_DIR}/${TARGET_NAME}/Application/Firebase/Staging/${GOOGLESERVICE_INFO_PLIST}

${PODS_ROOT}/FirebaseCrashlytics/run

if [ "${CONFIGURATION}" == "AppStore" ]
then
    echo "Setting up Crashlytics for App Store..."
    "${PODS_ROOT}/FirebaseCrashlytics/upload-symbols" -gsp "${GOOGLESERVICE_INFO_APP_STORE}" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
elif [ "$CONFIGURATION" == "Production" ]
then
    echo "Setting up Crashlytics for production..."
    "${PODS_ROOT}/FirebaseCrashlytics/upload-symbols" -gsp "${GOOGLESERVICE_INFO_PRODUCTION}" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
elif [ "$CONFIGURATION" == "Beta" ]
then
    echo "Setting up Crashlytics for beta..."
    "${PODS_ROOT}/FirebaseCrashlytics/upload-symbols" -gsp "${GOOGLESERVICE_INFO_BETA}" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
elif [ "$CONFIGURATION" == "Staging" ]
then
    echo "Setting up Crashlytics for staging..."
    "${PODS_ROOT}/FirebaseCrashlytics/upload-symbols" -gsp "${GOOGLESERVICE_INFO_STAGING}" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
else
    echo "Can't find matching GoogleService-Info.plist for Crashlytics configuration..."
fi

然后我的应用程序委托看起来像这样

@import Firebase;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [FIRApp configure];

    // Just put these in for testing

    [[FIRCrashlytics crashlytics] setCrashlyticsCollectionEnabled:NO];
    [[FIRCrashlytics crashlytics] checkForUnsentReportsWithCompletion:^(BOOL hasUnsentReports) {
        if (hasUnsentReports) {
            NSLog(@"-=-=-=-=- HAS UNSENT REPORTS -=-=-=-=-");
        } else {
            NSLog(@"-=-=-=-=- NO UNSENT REPORTS -=-=-=-=-");
        }
    }];

    if ([[FIRCrashlytics crashlytics] didCrashDuringPreviousExecution]) {
        NSLog(@"-=-=-=-=- APP CRASHED DURING LAST RUN -=-=-=-=-");
    }
    return YES;
}

进行测试。我从Xcode启动它,然后停止它,以便它与调试器分离。然后,我从模拟器启动它,然后按一个调用assert(NO);的按钮,它按预期崩溃。然后我再次从Xcode启动它,我总是只在调试器中看到该行:

-=-=-=-=- NO UNSENT REPORTS -=-=-=-=-

我不知道怎么了。起初我以为它不是将崩溃发送给Firebase,但现在我不认为它甚至没有发生崩溃,因为我一直看到没有未发送的报告。

任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

不幸的是,尽管官方文档说使用assert(NO);来测试您的集成,但我发现使用这种方法使应用程序崩溃实际上并没有为我生成崩溃报告

我使用了另一种方法来使应用程序崩溃,并且最终可以正常工作。

例如,NSLog([FIRCrashlytics crashlytics]);为我工作,但我真的期望其他任何事情(除了他们在文档中的断言)。