【问题标题】:IONIC2 Increment badges while app in background on android when push notification is received via fireBase当通过fireBase收到推送通知时,IONIC2在android后台应用程序时增加徽章
【发布时间】:2017-12-02 04:01:54
【问题描述】:

我有一个使用 firebase 和 cordova-plugin-badge 的 Ionic3 应用程序。 如果应用程序在前台运行并且我收到推送通知,则徽章编号会增加。

import { Badge } from '@ionic-native/badge';
declare let FCMPlugin;

constructor(private badge: Badge) {
  this.platform.ready().then(() => {
    FCMPlugin.onNotification((data) => {
      this.badge.increase(1); // works when app is in foreground
      if (data.wasTapped) {
        //Notification was received on device tray and tapped by the user.
        this.handleNotificationsWhenInBackground(data);
      } else {
        //Notification was received in foreground. Maybe the user needs to be notified.
        this.handleNotificationsWhenInForeground(data);
      }
    },
    (msg) => {
    },
    function (err) {
    });
  });
}

当应用程序处于后台但徽章编号未增加时,我会收到推送通知。如果我在应用程序处于后台时单击在 android 上收到的推送通知,则徽章编号会增加。因此,只有在应用处于前台时才会调用增加徽章编号的代码。

我的问题是:当应用程序在后台并且我收到推送通知时如何增加徽章编号。

【问题讨论】:

    标签: android firebase cordova-plugins ionic3 badge


    【解决方案1】:

    这样做的唯一方法是在通知负载中设置一个属性,例如,如果您使用的是 Android,则必须设置 "click_action":"FCM_PLUGIN_ACTIVITY" 属性才能在用户点击通知托盘后执行某些操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 2012-12-24
      • 2013-02-14
      相关资源
      最近更新 更多