You have to do it from the server side. In my case I have done it through php and mysql. Here is my database
I have added a field badgecount and i increase the badge count every time i send the push to the device with this code
$query = "SELECT badgecount FROM pushnotifications WHERE device_token = '{$device_token}'";
$query = $this->db->query($query);
$row = $query->row_array();
$updatequery = "update pushnotifications set badgecount=badgecount+1 WHERE device_token ='{$device_token}'";
$updatequery = $this->db->query($updatequery);
$device = $device_token;
$payload['aps'] = array('alert' => $pushmessage, 'badge' =>$row["badgecount"]+1, 'sound' => 'default');
$payload = json_encode($payload);
...
And I also make another api for making the badgcount 0 which is called in the
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
So when the notification is seen it is again zero in the server.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…