arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1.01k stars 1.56k forks source link

Notification Payload without message #1040

Open TdoubleG opened 5 years ago

TdoubleG commented 5 years ago

I have some troubles with the payload. What I want is that the payload show me the label that I sent from the firebase console. But this is what my payload looks like, even the message or title is not inside the payload

collapse_key: "app id"
from: "11111111"
google.delivered_priority: "high"
google.message_id: "0:xxxx%xxxxx"
google.original_priority: "high"
google.sent_time: 1554307094604
google.ttl: 00000
tap: true

This is an example from an Android Device I thought there is a body or something else where I can see the notification message payload. I'm printing out the response of the onNotificationOpen observable.

Does anybody knows the problem?

Ionic:

   ionic (Ionic CLI)             : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.1.1
   @angular-devkit/build-angular : 0.12.4
   @angular-devkit/schematics    : 7.3.5
   @angular/cli                  : 7.3.5
   @ionic/angular-toolkit        : 1.4.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 8.0.0, ios 5.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.0.0, (and 14 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/xxx/Library/Android/sdk)
   ios-deploy        : 1.9.2
   ios-sim           : 7.0.0
   NodeJS            : v10.9.0 (/usr/local/bin/node)
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2 Build version 10E125
felipeclopes commented 5 years ago

It depends on where you send the message in; this code snippet should be able to show you the actual data attached to the push notification:

this.firebase.onNotificationOpen().subscribe((response) => {
  this.handleNotification(response);
});
private async handleNotification(response) {
  // Whatever field you added to the push notification should be in the root
  console.log(JSON.stringify(response));
}
TdoubleG commented 5 years ago

@felipeclopes thank for your answer.

I don't really get it what you mean with "depends on where you send the message in". I have a notifications service with a function returning onNotificationOpen(). I'm calling this function inside my app.component.ts like this:

       // Listen to incoming messages
        this.pushService.listenToNotifications().subscribe( (res) => {
         console.log(res);
        });

and this is what my service looks like:

listenToNotifications() {
    return this.firebaseNative.onNotificationOpen()
  }
kevinswartz commented 5 years ago

Same problem here!

Ionic:

   ionic (Ionic CLI) : 4.12.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework   : ionic1 1.3.5
   @ionic/v1-toolkit : 1.0.22

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4, browser 5.0.4, ios 5.0.0
   Cordova Plugins       : cordova-plugin-ionic-webview 2.4.1, (and 24 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/xxx/Library/Android/sdk)
   ios-deploy        : 2.0.0
   ios-sim           : 7.0.0
   NodeJS            : v8.11.3 (/usr/local/bin/node)
   npm               : 5.6.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2 Build version 10E125