Closed AdamBrodzinski closed 9 years ago
You only need one sender per application you are sending notifications to, and you can send as many messages as you want from the sender. I agree that this could be clearer in the README.
I'll leave the issue open to have a look at improving the README.
Thanks for the clarification! I assumed this was the case but I wanted to double check I didn't create some kind of weird edge case bug :laughing:
I'm not sure if this makes it more clear for the overall example but here's an idea for the example application code block:
// setup a gcm server
//
var gcm = require('node-gcm');
var sender = new gcm.Sender('YOUR_API_KEY_HERE');
// function to send a push message
//
function sendPushMessage(opts) {
var message = new gcm.Message();
message.addData('title', opts.title);
message.addData('message', opts.message);
message.addData(opts.data);
var regIds = opts.regIds;
sender.send(message, regIds, function (err, result) {
if(err) console.error(err);
else console.log(result);
});
}
// send a test message
//
sendPushMessage({
title: "Hello Title",
message: 'Hello World',
regIds: ['1234'],
data:{key1: 'message1', key2: 'message2'}
});
The README has been improved.
It's kind of hard to tell from the readme, Should I be instantiating the sender every time I create a new message? Or can I instantiate it once and call sender.send multiple times?
Thanks! Adam