当我运行服务器并单击“发送”时。在服务器中,它显示发送“成功”,但我没有在我的android设备中收到任何通知。 控制台我得到如下:
Sending Successfully...
{ multicast_id: 6701351013026462000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [ { message_id: '0:1425279536646035%a80ac63e002efde3' } ] }
服务器/ app.js:
if(Meteor.isServer){
var gcm = Meteor.npmRequire('node-gcm');
var message = new gcm.Message({
collapseKey: 'demo',
delayWhileIdle: true,
timeToLive: 3
});
//create sender with My Project API Key
var sender = new gcm.Sender('AIzaSyCTrkiGnZBXwfGIJDzwcwWBZoImd5DRw');
var registrationIds = [];
// As of now manually i am giving my device registrationID
registrationIds.push('APA91bH9JCWmstRQ93FmZw6NlitI5-4kG1DPXHwrpIy0k8zWUlK2Ono0_8ULC2vOiFRkRgkY0s1IcatXU2jes0fwvuwxjBULX9HUmClDCkbqHtp0fwSh4I9igEC0CfglbEXmjpFI_ckp275adYZB16lAbR75bk6L2xf-OmsmoDig-gNaW88');
}
Meteor.methods({
'notify': function(title, msg) {
message.addData('title',title);
message.addData('message',msg);
sender.send(message, registrationIds, 10, function (err, result) {
if(err){
console.error(err);
}
else {
console.log("Sending Successfully...");
console.log(result);
}
});
}
});
的客户机/ app.js:
Template.form.events({
'click [data-action="send-notification"], submit': function (event, template) {
event.preventDefault();
Meteor.call('notify', template.$('[data-field="title"]').val(), template.$('[data-field="message"]').val(), function(err, res) {
console.log("I am from Client Event...");
console.log(res);
if (err) {
console.log(err);
} else {
if (res.userCount) {
alert('Notification sent.');
}
}
});
}
});
<head>
<title>My App</title>
</head>
<body>
{{> loginButtons}}
{{#if showForm}}
{{> form}}
{{/if}}
</body>
<template name="form">
<form>
<input type="text" data-field="title" placeholder="Title">
<input type="text" data-field="message" placeholder="Message">
<button data-action="send-notification">Send</button>
</form>
</template>