Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic set badge after push notification

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?

like image 509
crazybob Avatar asked Nov 09 '22 01:11

crazybob


1 Answers

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.

like image 119
MobileEvangelist Avatar answered Nov 25 '22 02:11

MobileEvangelist