Ionic1,推送通知到达时显示徽章计数

时间:2017-06-22 10:26:16

标签: cordova ionic-framework push-notification

我正在使用ionic 1 app并在其中实施推送通知。现在我正在尝试在应用程序图标上实现徽章,为此我使用的是cordova插件(Cordova Badge Plugin)。当推送通知到达时它正在工作,通过点击该通知,它打开了应用程序,我在那里实现了徽章逻辑。我这样编码。

$rootScope.$on('cloud:push:notification', function (event, data) {
            document.addEvenLtistener('deviceready', function () {
            cordova.plugins.notification.badge.requestPermission(function (granted) {
                cordova.plugins.notification.badge.set(10);
            });
            }, false);
            var msg = data.message;
            alert(msg.title + ': ' + msg.text);
        });

关闭应用程序时显示徽章,当我再次打开应用程序时,它会清除徽章,因此我知道徽章实际上是如何工作的。要清除徽章我正在做这样的代码。

        document.addEventListener('deviceready', function () {
             cordova.plugins.notification.badge.clear();
        }, false);

我想要的只是应用程序图标,以便在通知到达时显示徽章计数,此时它会显示计数但仅在我打开应用程序时。

0 个答案:

没有答案