Update Badge Count For Push Notifications in ios7

后端 未结 3 1420
时光取名叫无心
时光取名叫无心 2020-12-18 13:07

am working on push notifications app but badge count is not increasing when notification comes. i have saw so many examples in stack overflow

3条回答
  •  半阙折子戏
    2020-12-18 13:46

    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.

提交回复
热议问题