FirebaseApp.configure() 在启动时使应用程序崩溃

Mat*_*des 3 crash config objective-c ios firebase

我正在开发一个使用 Firebase 进行分析、crashlytics 和远程配置获取的 iOS 项目。对于依赖项管理,我使用 cocoapods 并且项目中当前版本的 Firebase 是最新的 - 6.22.0.

这里的问题是应用程序在配置 Firebase (ObjC -> [FIRApp configure];)的代码行上的每次新启动时崩溃。我已经看到了一些类似的帖子,但没有一个对我的情况有帮助,除非我遗漏了一些东西。

部分项目结构如下图所示。红色表示主要xcodeproj目标和应用程序的主文件。蓝色表示xcodeproj自定义框架的文件,其中包含帮助FirebaseAnalytics程序,包括用于分析日志记录的包装器,这意味着它具有其依赖性pod Firebase/Analytics。此自定义框架用于标有红色的主应用程序目标。(在pod install我总是打开之后xcworkspace,所以这是在xcworkspace)。

在此处输入图片说明

以下是Podfile.

target 'TheApp' do
    platform :ios, '11.0'
    project 'TheApp/TheApp.xcodeproj'
    use_frameworks!
    pod 'Firebase/Auth'
    pod 'Firebase/Core'
    pod 'Firebase/Messaging'
    pod 'Firebase/RemoteConfig'
end

target 'TheCustomFramework' do
    platform :ios, '11.0'
    project 'TheCustomFramework/TheCustomFramework.xcodeproj'
    use_frameworks!
    pod 'Firebase/Analytics'
end
Run Code Online (Sandbox Code Playgroud)

我在应用程序委托中添加了 Firebase 配置方法,如谷歌文档中所示。

在此处输入图片说明

另外,我已经GoogleService-Info.plist按照谷歌文档的说明在项目中添加了文件。

在此处输入图片说明

但是该应用程序不断在didFinishLaunchingWithOptions方法 in 中调用的 Firebase 配置上崩溃AppDelegate。当我在卡住的跟踪中更深入地输入时,我364th在 Firebase 库中标有红色矩形的代码行崩溃:

在此处输入图片说明

Xcode 控制台中此崩溃的异常消息是:

Terminating app due to uncaught exception 'com.firebase.installations', reason: 'The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. One way to ensure that is to call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).'
Run Code Online (Sandbox Code Playgroud)

这里可能是什么问题?感谢您的帮助和解答。

ps 很抱歉发这么长的帖子。

Mat*_*des 5

回答我自己的问题。我基本上通过Firebase/Core pod从每个项目/目标中删除Podfile并添加与主应用程序目标相关的所有 Firebase解决了这个问题,包括Firebase/Analytics pod(这意味着从每个其他项目/目标中删除它)。

运行后,pod install我将所有使用 FirebaseAnalytics 的文件从自定义框架移动到主项目(目标)。现在一切都按预期工作,并且调用[FIRApp configure];不会使应用程序崩溃。

Podfile 现在看起来像这样:

target 'TheApp' do
    platform :ios, '11.0'
    project 'TheApp/TheApp.xcodeproj'
    use_frameworks!
    pod 'Firebase/Analytics'
    pod 'Firebase/Auth'
    pod 'Firebase/Messaging'
    pod 'Firebase/RemoteConfig'
end

target 'TheCustomFramework' do
    platform :ios, '11.0'
    project 'TheCustomFramework/TheCustomFramework.xcodeproj'
    use_frameworks!
end
Run Code Online (Sandbox Code Playgroud)