Badge Count is not increasing for push notification.always badge count remains 1?

后端 未结 2 1099
时光取名叫无心
时光取名叫无心 2020-12-20 10:28

My app badge count in not increasing when app is in background for push notifications.Count increase by 1 only for the first push notification and always remains badge count

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-20 11:09

    You have to do it from the server side. In my case I have done it through php and mysql. Here is my database enter image description here

    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.

提交回复
热议问题