当应用程序处于前台时,FCM推送通知未收到,但是当应用程序处于后台时,则会收到FCM推送通知

时间:2017-09-20 13:46:33

标签: android firebase ionic-framework firebase-cloud-messaging

当应用程序处于前台时,推送通知不会被接收,但是当我在后台使用应用程序时,我会通过https://medium.com/@ankushaggarwal/gcm-setup-for-android-push-notifications-656cfdd8adbd

跟踪FCM教程

1 个答案:

答案 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);
    }
  }
}