Reputation: 501
My app does receive push notifications from GCM. There is then in my iOS device a number displayed on the icon equal to the amount or received notifications.
I'd like to clear this when opening the app. According to the documentation i have to use these lines of code:
push.clearAllNotifications(function() {
alert("1");
}, function() {
alert("2");
});
However, all code after this is not working and neither does one of the two alerts show. And ofcourse the number is still being displayed on the icon. Any tips or alternatives?
EDIT: My current code:
function startPush() {
var push = PushNotification.init({
android: {
senderID: "xxxx",
vibrate: true
},
ios: {
senderID: "951044503850",
gcmSandbox: false,
alert: "true",
badge: true,
sound: 'false',
clearBadge: "true"
}
});
push.on('registration', function(data) {
var regID = data.registrationId;
alert(regID);
//this works
});
push.clearAllNotifications(function() {
alert("1");
//does not fire
}, function() {
alert("2");
// does not fire
});
}
I do receive a registrationId so that part does work. HOwever the alert(1) or alert(2) do not fire so this part is not functional. BTW for bonus points ;), my phone doesn't vibrate on push notification either
Upvotes: 0
Views: 272
Reputation: 2384
Alternative Solution
Add Cordova Badge Plugin and set badge 0(zero) on app init
document.addEventListener('deviceready', function () {
cordova.plugins.notification.badge.set(0);
}, false);
Or wherever you want to hide icon's badges
Upvotes: 1