当时在iOS设备上收到通知时,应更改徽章,并在打开应用程序之前设置徽章。
我检查了这个ontotificationOpen()方法。但是当我点击通知时,它会打电话。
我使用cordova-plugin-firebase
。这是链接https://github.com/arnesson/cordova-plugin-firebase
但是,当在iOS设备上收到通知时是否有一种方法?
$ionicPlatform.ready(function() {
if (typeof FirebasePlugin != 'undefined') {
window.FirebasePlugin.subscribe("notficationsubscribe");
// Below method calls when i tap on notifcation and sets the badge number
window.FirebasePlugin.onNotificationOpen(function(data) {
window.FirebasePlugin.setBadgeNumber(4);
}
}
}
firebaseplugin.onnotificationopen()方法在我点击通知并设置徽章号时调用,但是我想在收到通知时设置徽章。
有人有想法吗?我该如何实现?
实际上我为其设置了逻辑。
1)我在数据库中存储了一个badgecounter值。
2)当我想在当时发送通知时,我会从数据库中检索
var badge = badgeCounter // it is an integer value
var notification = {
'title': 'Stock available',
'body': 'Click here to more details...',
'sound': 'default',
'badge': badge
};
3)点击或单击通知后,我使用以下内容清除了徽章。 window.FirebasePlugin.setBadgeNumber(0);
4),并且在数据库中i将值更新为'0'(零)。
因此,我解决了它,它对我非常有用。
您不用代码设置此设置,它将根据您的通知包含的内容进行设置。从服务器发送(firebase)时,您必须在通知有效载荷中包括"badge":1
(或任何数字)。我不确定它如何与Firebase一起使用,而是查看远程通知的文档。注意"徽章" -Key。