【问题标题】:Using react-native-push-notification, App crashes when receiving new FCM notification使用 react-native-push-notification,App 在收到新的 FCM 通知时崩溃
【发布时间】:2019-02-06 07:52:15
【问题描述】:

我试图在 react-native 应用程序上添加推送通知,所以我使用了 react-native-push-notification。库配置进行得很顺利,但是当收到通知时,APP 立即崩溃,说“FirebaseApp 未初始化”。

崩溃报告 AndroidRuntime:java.lang.IllegalStateException:默认 FirebaseApp 未在此 com.myapp 中初始化。请务必先调用 FirebaseApp.initializeApp(Context)。

如何初始化 FirebaseApp 或解决此问题?任何帮助将不胜感激。

有关更多信息,请参阅已打开的 Github 问题https://github.com/zo0r/react-native-push-notification/issues/852

【问题讨论】:

  • 您在哪里看到这个错误“FirebaseApp 未初始化”。我的应用程序崩溃了,但我不确定在哪里检查日志以找出导致它的原因>

标签: android firebase react-native firebase-cloud-messaging react-native-push-notification


【解决方案1】:

好的!现在可以了。

build.gradle

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:+'
    }
}

app/build.gradle

// At the very bottom of the file
apply plugin: 'com.google.gms.google-services'

信用https://github.com/zo0r/react-native-push-notification/issues/852#issuecomment-417641675

【讨论】:

  • 不修复 google-services 的版本可能(并且对我们而言)会导致将来出现问题。最好像这样修复版本:classpath 'com.google.gms:google-services:4.2.0'
【解决方案2】:

当我将我的 AndroidManifest.xml 更改为时它工作了

    <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application ....>
    <!-- Change the value to true to enable pop-up for in foreground on receiving remote notifications (for prevent duplicating while showing local notifications set this to false) -->
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                android:value="false"/>
    <!-- Change the resource name to your App's accent color - or any other color you want -->
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->

    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
    </receiver>

    <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

【讨论】:

    猜你喜欢
    • 2020-08-21
    • 2018-12-29
    • 1970-01-01
    • 2019-05-16
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    相关资源
    最近更新 更多