其中,YOUR_SENDER_ID应该被替换为您通过Google Cloud Console为应用注册的ID。
document.addEventListener("deviceready", function(){
var push = PushNotification.init({
android: {
senderID: "YOUR_SENDER_ID",
icon: "ic_notification",
iconColor: "#000000",
sound: true,
vibrate: true,
clearBadge: true
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
push.on('registration', function(data) {
console.log(data.registrationId);
});
push.on('notification', function(data) {
console.log(data.title+" Message: " +data.message);
alert(data.title+" Message: " +data.message);
});
push.on('error', function (e) {
console.log(e.message);
});
});
确保您的推送服务能够正确地将消息发送到您应用的设备上,并且应用能正确地接收并显示推送通知。