当应用程序处于前台时,推送通知不会被接收,但是当我在后台使用应用程序时,我会通过https://medium.com/@ankushaggarwal/gcm-setup-for-android-push-notifications-656cfdd8adbd
跟踪FCM教程答案 0 :(得分:0)
尝试这种方式并实施this plugin。
当设备准备就绪时,我解雇了这段代码:
pushNotification.register(
function (result) {
//Do some stuff
}, function (error) {
//Do some stuff on error
}, {
"badge":"true",
"sound":"true",
"alert":"true",
"ecb": "onNotificationAPN"
});
并且还实现了以下功能:
function onNotificationAPN(event) {
if (event) {
if ( event.alert ) {
alert(Recieved alert: + event.alert);
}
if ( event.sound ) {
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge ) {
pushNotification.setApplicationIconBadgeNumber(function() {
//SetApplicationIconBadgeNumber success.
}, function() {
//SetApplicationIconBadgeNumber error.
},
event.badge);
}
}
}