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

jpush
badge
ios
标签: #<Tag:0x00007fb83bfae740> #<Tag:0x00007fb83bfae600> #<Tag:0x00007fb83bfae4c0>

(Realm) #1

我在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

(Realm) #3

谢谢大佬,问题已解决,是因为代码没写对,需要在ready里才能拿到插件