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]
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.