ionic set badge after push notification

余生颓废 提交于 2019-11-30 17:34:03

问题


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?


回答1:


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.




回答2:


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

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