我有一个使用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上收到的推送通知,则会增加徽章编号。因此,仅当应用程序位于前台时才会调用增加徽章编号的代码。
我的问题是:当应用程序在后台时我如何增加徽章编号,并收到推送通知。
答案 0 :(得分:0)
执行此操作的唯一方法是在通知有效内容中设置属性,就像在Android上一样,您必须设置"click_action":"FCM_PLUGIN_ACTIVITY"
属性才能在用户点击通知托盘后执行某些操作。< / p>