【发布时间】:2018-07-16 10:28:49
【问题描述】:
我有一个使用 Firebase 推送通知的应用,当应用在前台和后台收到通知时,它可以正常工作。但是当我关闭/滑动应用程序时,它会崩溃。
这是关于崩溃的日志:
--------- beginning of crash
07-16 17:16:56.218 7552-7571/? E/AndroidRuntime: FATAL EXCEPTION: Firebase-RNFirebaseMessagingService
Process: com.tutorial, PID: 7552
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.tutorial. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source:53)
at com.google.firebase.messaging.zzb.zzb(Unknown Source:191)
at com.google.firebase.messaging.zzb.zzc(Unknown Source:2)
at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source:353)
at com.google.firebase.iid.zzg.run(Unknown Source:26)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:7)
at java.lang.Thread.run(Thread.java:764)
07-16 17:17:05.703 7552-7569/com.tutorial W/EnhancedIntentService: Service took too long to process intent: com.google.android.c2dm.intent.RECEIVE App may get closed.
在我的应用程序中,我实现了 2 种方法:
this.notificationListener = firebase.notifications().onNotification((notification) => {
senName = notification.data.senderName;
senUid = notification.data.senderUid;
const showNotif = new firebase.notifications.Notification()
.setNotificationId('notificationId')
.setTitle(notification.title)
.setBody(notification.data.text)
.android.setChannelId('channel_id_foreground')
.android.setSmallIcon('ic_launcher');
firebase.notifications().displayNotification(showNotif)
});
和
this.notificationOpenListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification = notificationOpen.notification;
if (!senName || !senUid) {
senName = notification.data.senderName;
senUid = notification.data.senderUid;
}
var roomUid = this.generateChatId(firebase.auth().currentUser.uid, senUid);
this.goToChatRoomWithId('ChatScreen', senName, senUid, roomUid);
});
有人知道这个问题吗?
【问题讨论】:
标签: firebase react-native push-notification firebase-cloud-messaging