I am developing iOS app with Phonegap.
I am implementing the process which incrementing badge number when app receives push notification usijng phonegap-plugin-push.
On the server side which sending push notification, the badge number is not configured.
I want to implement the process when app receives push notification, app counts the current badge number, increments it and set the badgenumber.
Using push.getApplicationIconBadgeNumber and push.setApplicationIconBadgeNumber, below my code works well when app is Foreground, But it doesn't work when app is Background, Suspended、Not running.
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
console.log('Received Device Ready Event');
console.log('calling setup push');
console.log('platform : '+device.platform);
if ((device.platform == 'iOS') || (device.platform == 'Android')) {
app.setupPush();
}
},
setupPush: function() {
console.log('calling push init');
var push = PushNotification.init({
"android": {
"senderID": "xxxxxxxxxx"
},
"browser": {},
"ios": {
"sound": true,
"vibration": true,
"badge": true
},
"windows": {}
});
push.on('registration', function(data) {
console.log('registration event: ' + data.registrationId);
var oldRegId = localStorage.getItem(key);
console.log('oldRegId : ' + oldRegId);
if (oldRegId !== data.registrationId) {
console.log('different ID');
localStorage.setItem(key, data.registrationId);
}
});
push.on('error', function(e) {
console.log("push error = " + e.message);
});
push.on('notification', function(data) {
console.log('notification event');
navigator.notification.alert(
data.message, // message
null, // callback
data.title, // title
'Ok' // buttonName
);
push.getApplicationIconBadgeNumber(function(count) {
console.log('get badge : ' + count);
count++;
push.setApplicationIconBadgeNumber(function() {
console.log('set badge : ' + count);
}, function() {
console.log('set badge error');
}, count);
}, function() {
console.log('get badge error');
});
});
}
};
On this site,
push.setApplicationIconBadgeNumber is explained "Set the badge count visible when the app is not running", and push.getApplicationIconBadgeNumber is explained "Get the current badge count visible when the app is not running".
But this my code, both 2 function works when app is Foreground, and the badge number is not changed when app receives push notification on background state.
So, is the explanation written on that site wrong?
App works the same, nevertheless the push notification option "content-available" is configured 1 or not on the push notification sending server side.
So, please tell me what the code should I write.
-- Versions --
crodova version : 7.1.0
platform iOS : 4.5.4
phonegap-plugin-push : 1.10.6