React-native FCM:当应用程序处于后台或被杀时,无法访问通知数据

Del*_*Del 7 push-notification android-notifications react-native firebase-cloud-messaging react-native-fcm

我正在尝试使用firebase云消息传递和反应本机应用程序使反应本机fcm工作.

我主要关注Android

react-native@0.48.0
react-native-fcm@10.0.2
OS: Android - Emulator - 7.0.2
Run Code Online (Sandbox Code Playgroud)

当我的应用程序处于前台时,它的工作正常,我在此功能中收到数据

FCM.on(FCMEvent.Notification, async (notif) => {

我可以处理一切

图片

但是当应用程序处于后台时,会收到通知,但是当我点击横幅时,应用程序进入前台,触发相同的功能,但是notif对象不同,并且不包含我的数据.

图片

当应用程序被杀死时,也会收到通知,但是当我点击横幅时,应用程序启动, FCM.getInitialNotification() 触发,并且我的notif对象也不包含数据,行为与后台相同

图片

我正在使用firebase web界面的node-gcm库测试消息的格式,但没有任何作用.

这是我的消息示例,但我尝试了大量的组合:

let message = new gcm.Message({
    priority: 'high',
    content_available: true,
    timeToLive: 3,
    data: {
        key1: 'message1',
        key2: 'message2'
    },
    notification: {
        title: "Hello, World",
        icon: "ic_launcher",
        body: "This is a notification that will be displayed if your app is in the background."
    },
    custom_notification: {
        key1: 'message1',
        key2: 'message2'
    }

});
Run Code Online (Sandbox Code Playgroud)

在这些情况下,我该如何继续发送和接收数据?因为让我抓狂.

如果您需要更多数据,请索取:)

谢谢!!

Dav*_*rte 3

就我而言,在前台通知事件 firebase.notifications().onNotification 上构建通知时,我缺少通知的数据设置

new firebase.notifications.Notification()
      .setNotificationId(fcmNotification.data.notificacionId)
      .setTitle(fcmNotification.title)
      .setBody(fcmNotification.body)
      .setData(fcmNotification.data) // <- this little bastard
Run Code Online (Sandbox Code Playgroud)

因此,当点击时,即使传入的 json已填充数据字段,通知data也未定义firebase.notifications().onNotificationOpenedfirebase.notifications().onNotification