ionic set badge after push notification

对着背影说爱祢 提交于 2019-11-30 23:12:17

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!