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

橙三吉。 提交于 2019-11-29 13:05:26

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.

You said your payload is :

aps = { alert = "third testing"; badge = 1; sound = "sound.caf"; };

Since you always send 1 for badge count, that's the badge count being displayed for your app. The badge count is not incremental. If you want to see badge counts higher than 1, your server should put values higher than 1 in your payload.

Your server should keep track of which badge count each device should receive. The app itself is not guaranteed to receive all the push notifications, so you can't rely on its logic to update the badge count.

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