strongloop/loopback-component-push

No Content in notification on GCM

Closed this issue · 8 comments

Hey all,

So running the example app (server-2.0) and sending a push notification works great on iOS but when sent to Android devices, the push has no content.

{
  "deviceType": "ios",
  "deviceToken": "__token__",
  "alert": "test message",
  "badge": 1,
  "sound": "ping.aiff",
  "expirationInterval": 3600
}

--> I see a push notification on my iPhone saying "test message"

{
  "deviceType": "android",
  "deviceToken": "__token__",
  "alert": "test message",
  "badge": 1,
  "sound": "ping.aiff",
  "expirationInterval": 3600
}

--> I see a push notification on my android device saying "" (no content)

Am I missing something with regards to content?

According to http://developer.android.com/google/gcm/server.html#params there is no specific data member for the message...


I did notice that in apns.js and gcm.js the iteration over the notification object members does not do anything:
gcm.js:

Object.keys(notification).forEach(function (key) {
    if (notification[key] != null) {
      message.addData(key, notification[key]);
    }
  });

--> message.data is undefined
apns.js

Object.keys(notification).forEach(function (key) {
    note.payload[key] = notification[key];
  });

--> note.payload is undefined

@glesage thank you for reporting the issue. Can you reproduce the problem using the 1.x server in "example/server" too?

@raymondfeng you are the author of the server-2 example, could you PTAL?

@bajtos yes I was able to reproduce on 1.x server... it seems to be specific to the "alert" data member...

On android:

{
  "deviceType": "android",
  "deviceToken": "__token__",
  "alert": "test message",
  "message": "test message",
  "badge": 1,
  "sound": "ping.aiff",
  "expirationInterval": 3600
}

alert does not get sent through... but message does.
--> I guess this should just be specified in some doc so others know (:

I guess this should just be specified in some doc so others know

@crandmck can you please take care of that?

At the moment, we have only jsdoc comments mentioning this fact, albeit not very clearly:

/**
* (iOS only)
* The notification's message.
*/
alert: 'any',

I think it would be best to include the Notification object in http://apidocs.strongloop.com/loopback-component-push and rework the comments to follow the apidocs format.

ritch commented

The formatting of the JSDoc is just a bit off. I think @crandmck is fixing.

@bajtos I fixed the JSdoc. I added the message property to Notification, even though I didn't see it in the code. Please review and if it looks OK, please npm publish the module to update the API docs.

Oh ok great thanks!

Released in loopback-component-push@1.4.4