Visitar URL original
Background notification OK, but event "notification" never called · Issue #387 · phonegap/phonegap-plugin-push · GitHub
Skip to content
This repository was archived by the owner on Sep 4, 2020. It is now read-only.
This repository was archived by the owner on Sep 4, 2020. It is now read-only.

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

Closed

Description

@cmillauriaux

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
      });

Activity

  1. macdonst commented on Nov 30, 2015

    @macdonst
    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."
          }
        });
  2. cmillauriaux commented on Nov 30, 2015

    @cmillauriaux
    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 !

  3. macdonst commented on Nov 30, 2015

    @macdonst
    Member

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

  4. fredgalvao commented on Nov 30, 2015

    @fredgalvao
    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.

  5. fredgalvao commented on Nov 30, 2015

    @fredgalvao
    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.

  6. self-assigned this
    on Nov 30, 2015
  7. macdonst commented on Nov 30, 2015

    @macdonst
    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.

  8. added this to the Release 1.5.0 milestone on Dec 7, 2015
  9. fredgalvao commented on Dec 8, 2015

    @fredgalvao
    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)?

  10. macdonst commented on Dec 8, 2015

    @macdonst
    Member

    @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.

  11. MichaelJCole commented on Mar 19, 2016

    @MichaelJCole

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

    Is it still open?

  12. macdonst commented on Mar 20, 2016

    @macdonst
    Member

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

  13. sam2x commented on Feb 16, 2017

    @sam2x

    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.

  14. lock commented on Jun 4, 2018

    @lock

    This thread has been automatically locked.

  15. locked as resolved and limited conversation to collaborators on Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions