[英]IONIC2 Increment badges while app in background on android when push notification is received via fireBase
I have a Ionic3 app using firebase and cordova-plugin-badge.我有一个使用 firebase 和 cordova-plugin-badge 的 Ionic3 应用程序。 If the app is running in the foreground and I receive a push notification the badge number is increased.
如果应用程序在前台运行并且我收到推送通知,则徽章编号会增加。
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) {
});
});
}
I receive the push notification when the app is in the background but badge number is not incremented.当应用程序处于后台但徽章编号未增加时,我会收到推送通知。 If I click on the push notification received on android while the app is in the background then badge number is incremented.
如果我在应用程序处于后台时单击在 android 上收到的推送通知,则徽章编号会增加。 So the code to increment the badge number is called only when the app is in foreground.
因此,仅当应用程序处于前台时才会调用增加徽章编号的代码。
My problem is: how to increment the badge number while the app is in the background and I receive a push notification.我的问题是:当应用程序在后台并且我收到推送通知时如何增加徽章编号。
唯一的方法是在你的通知负载中设置一个属性,就像你在 Android 上一样,你必须设置"click_action":"FCM_PLUGIN_ACTIVITY"
属性以在用户点击通知托盘后启用一些操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.