Cordova-plugin-firebase: undefined: onNotificationOpen(notification.body) from Notification Center

Created on 22 Sep 2017  路  9Comments  路  Source: arnesson/cordova-plugin-firebase

Android-device 5.1
Cordova 7.0.1

If you open the notification from the Notification Center, the "notification.body" gets "undefined" on the callback of onNotificationOpen

Most helpful comment

Something weird is going on.

When the app is in the foreground it uses data sent in the notification payload, but when the app is in the background it uses data sent in the data payload.

Consider this code sent through their API:

{
    "to" : "<DEVICE TOKEN>"
    , 
    "notification": {
        "title": "This is used in the foreground",
        "body": "This is used in the foreground"
    },
    "data":{
          "title":"This is used in the background",
          "body":"This is used in the background"
        }
}

It seems as though the interface in the Firebase Backend is using the notification payload.

All 9 comments

Android 6.0.1
Cordova 7.0.1

I'm having the same problem. This only happens when clicking on the notification when the app is in the background.

onNotificationOpen parameters when app in foreground:

{
  body: "test2",
  key: "value",
  tap: false,
  title: "test2 title"
}

onNotificationOpen parameters when app in background and clicking on notification:

{
  collapse_key: "xxx.xxx.xxxxxxxx",
  from: "/topics/testing",
  google.message_id: "0:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  google.sent_time: 1507896870332,
  key: "value",
  tap: true
}

Is this the intended behavior? Is there any way to enable body and title?

Something weird is going on.

When the app is in the foreground it uses data sent in the notification payload, but when the app is in the background it uses data sent in the data payload.

Consider this code sent through their API:

{
    "to" : "<DEVICE TOKEN>"
    , 
    "notification": {
        "title": "This is used in the foreground",
        "body": "This is used in the foreground"
    },
    "data":{
          "title":"This is used in the background",
          "body":"This is used in the background"
        }
}

It seems as though the interface in the Firebase Backend is using the notification payload.

To clarify,

When the app is in the background, it uses the data in the notification payload to show the notification and when the user clicks the notification it instead uses the data in the data payload

After looking through the Firebase documentation I discovered this statement:

FCM can send a notification message including an optional data payload. In such cases, FCM handles displaying the notification payload, and the client app handles the data payload.
Source: https://firebase.google.com/docs/cloud-messaging/concept-options

So this behavior seems to be by design.

It is still handled weird and not very transparent in this plugin.

If the notification is received while the app is in the foreground it uses the notification payload in app and if the app is the background it uses the data payload in the app.

It is able to handle this in your app implementation, but the plugin really should handle this. I tried to fiddle around with the plugin, but I couldn't get the data through to the JS

Closing for cleanup. Please test with the latest version and reopen if it is still an issue.

I am having the same problem with the latest version. any solution?

Thanks,

Closing for cleanup. Please test with the latest version and reopen if it is still an issue.

I am having the same problem with the latest version. any solution?

Thanks in Advance,

Did you solve it @MuraliVegesna

Was this page helpful?
0 / 5 - 0 ratings