【问题标题】:FCM Push notification didn't receive when app is in foreground but receive when app in background应用程序在前台时未收到 FCM 推送通知,但在应用程序在后台时收到
【发布时间】:2017-09-20 13:46:33
【问题描述】:
【问题讨论】:
标签:
android
firebase
ionic-framework
firebase-cloud-messaging
【解决方案1】:
以这种方式尝试并实现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);
}
}
}