I'm using IONIC
Framework and I'd like to set the badge of my application after I'm getting push notification.
Is there a way to do it when my application is closed?
it is for others who will run into the same problem. I believe your talking about making badge visible with the updated badge number you've received from server.
First thing to enable it in code in init method of Push like this
var push = PushNotification.init({
android: {
senderID: senderID,
icon: 'pushicon',
sound: "true",
iconColor: "#ED8B00"
},
browser: {
pushServiceURL: 'url'
},
ios: {
alert: "true",
**badge: "true",**
sound: "true"
},
windows: {}
});
In above code we've enabled badge {will be displayed in all iPhones and supported Android Phones as well}
Now from server side. add below part to your ios portion so will get the updatd count even your your app is in background.
This is for ios only, please add for android as per your requirements;
{
"aps": {
"alert": {
"title": "Received",
"body": "You have received a message from Kens"
},
"badge": 66
},
"received_id": "9223",
"pn_type": "RECEIVED"
}
This badge count will automatically get updated to apps badge count even app is in background.(but badge field should be in integer).
Thanks hope this helps and solve your problem.
I had the same problem, resolved this by hitting the POST url from postman instead of the UI given on apps.ionic.io and it worked
来源:https://stackoverflow.com/questions/33744471/ionic-set-badge-after-push-notification