我就奇怪啦,为啥我的iOS的Badge清不掉咧?

realmx
2017-08-07 07:55 1.2k 0

我在ionic里用的,插件是jpush-phonegap-plugin@3.2.3,是我的姿势不对嘛?


问题已解决,是因为我代码没写对,在ready里才能拿到插件
正确代码如下

'use strict';
angular.module('app').run(function ($window, $ionicPlatform, $ionicPopup) {
    var $jpush,
        clearBadge = function () {
            $jpush.resetBadge();
            $jpush.setApplicationIconBadgeNumber(0);
        };
    $ionicPlatform.ready(function () {
        $jpush = window.plugins && window.plugins.jPushPlugin || {};
        $jpush.init();
        clearBadge();
    });
    $ionicPlatform.on('resume', clearBadge);
    document.addEventListener('jpush.openNotification', function (event) {
        $ionicPopup.alert({
            title: 'openNotification',
            template: JSON.stringify(event)
        });
    }, false);
    document.addEventListener('jpush.receiveNotification', function (event) {
        $ionicPopup.alert({
            title: 'receiveNotification',
            template: JSON.stringify(event)
        });
    }, false);
    document.addEventListener('jpush.backgroundNotification', function (event) {
        $ionicPopup.alert({
            title: 'backgroundNotification',
            template: JSON.stringify(event)
        });
    }, false);
    document.addEventListener('jpush.receiveMessage', function (event) {
        $ionicPopup.alert({
            title: 'receiveMessage',
            template: JSON.stringify(event)
        });
    }, false);
});

2个回答

热门排序