Closed mauron85 closed 8 years ago
What is this method, sendAsync
, you are using? I assume that's the pomisify-version...
In your first example your message is in push.message
, in the new code you are using push.body
. Are you sure push.body
is defined?
In the new code, timeToLive
should still be in ms, you have defined it in seconds. Your messages won't be delivered in 3 ms, so it fails.
Thank you for your assistence. Here are the anwers.
What is this method, sendAsync, you are using? I assume that's the pomisify-version...
yes, sendAsync is promisified version of send (i'm using bluebird lib for this).
In your first example your message is in push.message, in the new code you are using push.body. Are you sure push.body is defined?
yes, it's defined. I've replaced variable name from message to body to better match with node-gcm and google gcm varlable names.
In the new code, timeToLive should still be in ms, you have defined it in seconds. Your messages won't be delivered in 3 ms, so it fails.
ok, need to try this one. will let you know if it helps.
timeToLive increased to 3000ms and messages still not delivered
I've joined together old with new code. Every time I send msg it works and everytime I send msg2 it is not.
function sendPush (push) {
var sender = new gcm.Sender(settings.gcm.apikey);
var msg = new gcm.Message();
msg.addData('title', push.title);
msg.addData('message', push.body);
msg.addData('msgcnt','3'); // Shows up in the notification in the status bar
msg.collapseKey = 'mapilary';
msg.timeToLive = 3000;// Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
var msg2 = new gcm.Message({
collapseKey: 'mapilary',
timeToLive: 3000, // Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
notification: {
title: push.title || 'title',
body: push.body || 'body',
icon: 'ic_launcher'
}
});
console.log('Sending push notification', msg.toJson());
console.log('Sending push notification2', msg2.toJson());
return sender.sendAsync(msg, push.recipients); // this is working
//return sender.sendAsync(msg2, push.recipients); this is not :-(
}
Also this is the result of message toJson() for old and new code.
Push message msg (old)
{ data:
{ title: 'Aktualizovaná zásielka',
message: 'AD-55dc99e4022362072317520e',
msgcnt: '3' }
}
Push message msg2 (new)
{ collapse_key: 'mapilary',
time_to_live: 3000,
notification:
{ title: 'Aktualizovaná zásielka',
body: 'AD-55dc99e4022362072317520e',
icon: 'ic_launcher' }
}
No sure why, but data works fine.
var msg2 = new gcm.Message({
collapseKey: 'mapilary',
timeToLive: 3000, // Duration in seconds to hold in GCM and retry before timing out. Default 4 weeks (2,419,200 seconds) if not specified.
data: {
title: push.title || 'title',
message: push.body || 'body'
}
});
BTW I'm using https://github.com/phonegap/phonegap-plugin-push on the client side (but should not be related to my problem)
And one more remark. Example in README.md is using timeToLive: 3. Which is confusing or incorrect.
I would appreciate a PR on the timeToLive
in the README --- good catch!
Are you sure phonegap push supports the new notification-field? This was added in the most recent version of GCM. See here: https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages
Maybe that's the problem - no support in phonegap. I have just posted my question on phonegap-plugin-push - https://github.com/phonegap/phonegap-plugin-push/issues/87
Cool :) Hope they can clear that up. Can I get you to make a PR on the README? :)
Now I'm confused, because google gcm docs states that time_to_live is in seconds.
Hum -- that is probably right. To be honest, I didn't check it, I just assumed your old example was correct, and I know that the timeToLive implementation in node-gcm hasn't changed.
No problem. Will cancel PR.
This is not a bug in node-gcm. The push plugin for Cordova is expecting the notification to come via the data message format. I know this for certain as I'm the maintainer of the phonegap-plugin-push repo.
This issue should be closed.
Fixed in the push plugin https://github.com/phonegap/phonegap-plugin-push/issues/87
Great --- thanks for the info, @macdonst.
In summary: notification
works in phonegap-plugin-push 1.2.1.
Thank you guys for clarification. Great support from both of you.
After upgrade from 0.9.7 to 0.11.1 I don't receive push notifications in my cordova app. According to node-gcm server messages are sent fine (success=1 and message_id is assigned), but they're not delivered to android device.
All node-gcm versions up to 0.11.1 are working with the old code for version 0.9.7, but not with new code.
For version 0.9.7 I have old code (which is still working)
And for 0.11.1 I've adjusted the code to: