Page 1 of 1

setApplicationIconBadgeNumber not resetting

Posted: Fri Oct 10, 2014 7:48 pm
by Joseph Francis

I have followed code hinted at in the support site here to the letter in my application, but I do not seem to be able to reset the badge count.

myAlert(data.aps.alert, "Notification", "OK"); /* handle notification /
myAlert("notification clearing badges"); / debug only /
var pushNotification = window.plugins.pushNotification; / per specification /
pushNotification.setApplicationIconBadgeNumber(null, null, 0); / per cordova spec */

furthermore, if I try to reset the badge on a "device ready" event, the "pushNotification" object is undefined:

myAlert("device ready clearing badges");
var pushNotification = window.plugins.pushNotification;
try {
pushNotification.setApplicationIconBadgeNumber(function(){myAlert("Badge Cleared");},
function(){myAlert("Badge Cleared Error");}, 0);
}
catch(err) {
myAlert(err.message);
}

this gives me simply an

"undefined is not an object (evaluationg '|.setApplicationIconBadgeNumber')"

error on my phone. the object "pushNotification" would not seem to exist on the plugins list.

Any help from the team - ?


setApplicationIconBadgeNumber not resetting

Posted: Fri Oct 10, 2014 8:40 pm
by Kateryna Grynko

Hi Joseph,

Please check this thread:
https://getsatisfaction.com/apperyio/...


setApplicationIconBadgeNumber not resetting

Posted: Mon Oct 13, 2014 11:03 am
by Joseph Francis

Kateryna, with all due respect, I don't need a redirect to a past post, I've read all of them, and you and the rest of staff (example, Evgene, and Oleg) give conflicting answers. I need a definitive answer on how to use the function. No prior answer works.

None work for my application, an I have an extremely simple need.
On "Device Ready" trigger I execute the following javascript, which is referenced by no fewer than five posts:

---

var pushNotification = window.plugins.pushNotification;
pushNotification.setApplicationIconBadgeNumber(0, function(){});

---

Nothing happens of course (I don't need to give a list of postings where other people say exactly the same thing.)

You have said in a previous post

var pushNotification = window.plugins.pushNotification;
pushNotification.setApplicationIconBadgeNumber(successHandler, 0);

===

this cannot work because it doesn't match the definition of the plugin.

Let's look at the plugin:

// Call this to set the application icon badgePushNotification.prototype.setApplicationIconBadgeNumber = function(badge, callback) {
cordova.exec(callback, callback, "PushNotification", "setApplicationIconBadgeNumber", [{badge: badge}]);
};

therefore you must call the function with the badge first, then the callback.

===

I create a function triggered on callback to see what is going on:

[quote:]function myHandleReady() { alert("device ready clearing badges");


Code: Select all

setTimeout(
    
    function() {
        
        var pushNotification = window.plugins.pushNotification;
        
        alert("device id " + localStorage.getItem('pushNotificationDeviceID'));
        alert("token " + localStorage.getItem('pushNotificationToken'));
        
        var pushNotification = window.plugins.pushNotification;
        alert("pushNotification " + window.plugins.pushNotification);
        
        alert('Try like Oleg');
        try {
            pushNotification.setApplicationIconBadgeNumber(0);
        } catch (err) {
            alert("created error " + err);
        }
        
        alert("Try like Kateryna");
        try {
            pushNotification.setApplicationIconBadgeNumber(function() {}, 0);
        } catch (err) {
            alert("created error " + err);
        }
        
        alert("Try like Evgene");
        try {
            pushNotification.setApplicationIconBadgeNumber(0, function() {});
        } catch (err) {
            alert("created error " + err);
        }
                    
    }, 1000);

}[/quote]
ImageImageImageImage

You'll notice that, while I'm registered for push, and have a token, there is no window.plugins.pushNotification object, therefore none of the subsequent calls work because there is no object to call with.

So, back to my original question:

What is the definitive way to reset a badge when you use push notifications?

none of the varieties of calls in all postings on the subject work because I have no "pushNotification" object in my plugins.


setApplicationIconBadgeNumber not resetting

Posted: Tue Oct 14, 2014 8:17 pm
by Evgene Karachevtsev

Hello Joseph,

Please try this:
prePushNotification.setApplicationIconBadgeNumber(0, function () {});/pre


setApplicationIconBadgeNumber not resetting

Posted: Thu Oct 16, 2014 12:50 am
by Joseph Francis

Thanks Evgene - this is the definitive answer and works in my application.

Perhaps there's a way to publish this and supercede all the other answers which cause confusion.


setApplicationIconBadgeNumber not resetting

Posted: Thu Oct 16, 2014 5:59 am
by Kateryna Grynko

Hi Joseph,

Glad it works for you!
Thank you for a suggestion, marked as official answer.