Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Background notification OK, but event "notification" never called #387

Closed
cmillauriaux opened this issue Nov 30, 2015 · 12 comments
Closed
Assignees
Labels
Milestone

Comments

@cmillauriaux
Copy link

Hi everyone,

I installed the plugins and configure android notifications, but, when i send a notification from my server (node-gcm), the notification is shown in the navbar like the application is in the background. If i click in this notification, nothing happened. The most important is if i add a console.log instruction in the "notification" event, nothins is print in the console. So, i think my notification message is never catch by the plugin. Any idea ?

Server message :

var message = new gcm.Message({
      collapseKey: "applice",
      delayWhileIdle: true,
      timeToLive: 3,
      notification: {
        title: "Hello, World",
        icon: "icon",
        message: "This is a notification that will be displayed ASAP."
      }
    });

Client side :

self.push = PushNotification.init({
        android: {
          senderID: "blablablabla"
        }
      });

      self.push.on('registration', function(data) {
        console.log('REGISTRATION : ' + JSON.stringify(data));
        if (data && data.registrationId && data.registrationId.length >
          0) {
          // Call token server update
        }
      });

      self.push.on('notification', function(data) {
        console.log('MESSAGE : ' + JSON.stringify(data));
        // Call client user refresh
      });
@macdonst
Copy link
Member

@cmillauriaux trying sending this instead and let me know what you find. I recently discovered that Google will just eat messages sent using the "notification" property and not pass them on to the push handler.

var message = new gcm.Message({
      collapseKey: "applice",
      delayWhileIdle: true,
      timeToLive: 3,
      data: {
        title: "Hello, World",
        icon: "icon",
        message: "This is a notification that will be displayed ASAP."
      }
    });

@cmillauriaux
Copy link
Author

@macdonst you're my hero ! Thanks a lot !

I searched desperatly on the plugin side, but it was on the server side. You saved my day !

@macdonst
Copy link
Member

@cmillauriaux sorry about that, I need to document it better cc: @fredgalvao

@fredgalvao
Copy link
Collaborator

@macdonst Funny thing, neither of these are technically wrong.

Check node-gcm's usage doc and the official docs on gcm, and you'll see that data and notification are both declared.

  • data: is supposed to hold extra info, that is passed to the intent on android or to the AppDelegate application:didReceiveRemoteNotification: event on iOS. message, title or icon are not supposed to live on this object.
  • notification: has its own scheme

Now, if what you said is that for some reason we cannot trust in the notification object, I think this should be reported as a bug to google or we're missing something about the handler stuff.

@fredgalvao
Copy link
Collaborator

Oh, I guess I understand now. There is a distinction between data payload and notifications payload on the docs. Source.

Notification payload

GCM automatically displays the message to end user devices on behalf of the client app.
Notifications have a pre-defined set of user-visible keys.

Data payload

Client app is responsible for processing data messages.
Data messages have only custom key/value pairs.

So, I'm assuming that we want to handle everything by ourselves, which leaves us requiring the data payload in every situation.

Use data messages when you want to handle the display or process the messages on your Android client app,
or if you want to send messages to iOS devices when there is a direct GCM connection.

I'll update the docs with a topic on this soon.

@fredgalvao fredgalvao reopened this Nov 30, 2015
@fredgalvao fredgalvao self-assigned this Nov 30, 2015
@macdonst
Copy link
Member

@fredgalvao Yup, I found that out while writing a service to send messages using node-gcm. It really tripped me up for awhile. Yes, we will need to be more opinionated and have people use the data property in their payload instead of notification.

@macdonst macdonst removed the question label Nov 30, 2015
@macdonst macdonst added this to the Release 1.5.0 milestone Dec 7, 2015
@fredgalvao
Copy link
Collaborator

@macdonst , does your comment here has anything to do with this? From what I understood, we cannot simply tell users to ignore the notification object. Or was that comment only for iOS (which makes me think that we need to have pure data objects in android only)?

@macdonst
Copy link
Member

macdonst commented Dec 8, 2015

@fredgalvao Yeah, there is an issue with data/notification in that Android and iOS don't treat them the same. I opened #401 to do some testing in the 1.5.x branch. They really should work the same.

@MichaelJCole
Copy link

FYI: https://github.com/ToothlessGear/node-gcm#gcm-client-compatibility lists this as an open bug (Jan 2016).

Is it still open?

@macdonst
Copy link
Member

@MichaelJCole send everything in the data part of the payload, not the notifcation part.

@sam2x
Copy link

sam2x commented Feb 16, 2017

Hey, anyone experiencing my case ?

  • When using data part only, i got sound + only title (no message, nor body)
  • When using notification part, i got title + message body of the notification, but no sounds....

Tried a combinaison of all of them, no luck too.

@lock
Copy link

lock bot commented Jun 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants