【问题标题】:FCM Push notification didn't receive when app is in foreground but receive when app in background应用程序在前台时未收到 FCM 推送通知,但在应用程序在后台时收到
【发布时间】:2017-09-20 13:46:33
【问题描述】:

当应用程序在前台时不会收到推送通知,但在应用程序在后台时会收到我已按照https://medium.com/@ankushaggarwal/gcm-setup-for-android-push-notifications-656cfdd8adbd 的 FCM 教程进行操作

【问题讨论】:

  • 您正在尝试哪种设备?
  • Android 6.0 设备

标签: 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);
    }
  }
}

【讨论】:

    猜你喜欢
    • 2020-12-23
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 2021-09-08
    相关资源
    最近更新 更多