繁体   English   中英

当应用程序在前台时未收到FCM推送通知,但在应用程序在后台时收到

[英]FCM Push notification didn't receive when app is in foreground but receive when app in background

当App处于前台时不会收到推送通知,但是当App处于后台时则收到推送通知,我已经按照https://medium.com/@ankushaggarwal/gcm-setup-for-android-push-notifications-656cfdd8adbd

以这种方式尝试并实现此插件

当设备准备就绪时,我会触发以下代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM