7

Im am trying to make work react-native-fcm, with firebase cloud messaging and a react-native app.

I am focusing mainly in Android

react-native@0.48.0
react-native-fcm@10.0.2
OS: Android - Emulator - 7.0.2

When my app is in foreground, its working perfectly, I receive the data in this function

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

And I can handle everything

image

But when the app is in background, the notification is received, but when I tap the banner, the app goes foreground, the same function is triggered, but the notif object is different, and don't contains my data.

image

When the app is killed, also the notification is received, but when I tap the banner, the app starts, the FCM.getInitialNotification() is triggered, and my notif object doen't also contain the data, the same behaviour than in background

image

I am testing the format of the messages using node-gcm library, of firebase web interface, but nothing works.

This is a sample of my message, but I have tryed tons of combinations:

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'
    }

});

How should I proceed to send and receive data in those cases? Because is driving me crazy.

If you need more data, ask for it :)

Thanks!!

Víctor
  • 3,029
  • 3
  • 28
  • 43
  • 1
    did u get any solution, I am also facing the same issue, If u get please add your answer here. – Sandeep Mishra Feb 23 '18 at 12:06
  • It was a problem related of using two intents inside the android code (I used the another one for splash screen): At the moment that I leave the code with only one intent, it follows the good behaviour – Víctor Feb 26 '18 at 16:09
  • https://stackoverflow.com/questions/49026676/showing-fcm-notification-message-in-json-format-when-app-is-killed-or-in-backgro please check this once if u have any solution. I am not using any Splash activity in android part. – Sandeep Mishra Feb 28 '18 at 10:04

1 Answers1

3

in my case, i was missing the notification's data setup when building the notification on foreground notification event firebase.notifications().onNotification

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

so, when tapping the notification data was undefined on firebase.notifications().onNotificationOpened even when the json that comes in firebase.notifications().onNotification had data field filled

David Rearte
  • 764
  • 8
  • 19