The counter icon does not increase for push notification.always does the counter remain 1?

The icon of my application’s icon does not increase when the application is in the background for push notifications. Increasing the number by 1 only for the first push notification and always remains the icon value as 1 if I receive more than one notification, and also only to return the icon 1 only, Below is my code

- (void)application:(UIApplication *)application 
       didReceiveRemoteNotification:(NSDictionary *)userInfo {

    NSString *message = nil;
    id alert = [userInfo objectForKey:@"aps"];
    if ([alert isKindOfClass:[NSString class]]) {
        message = alert;
    }    
    else if ([alert isKindOfClass:[NSDictionary class]]) {
        message = [alert objectForKey:@"alert"];
    }
    if (alert) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"xyz"
                                                        message:message
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:@"Cancel", nil];
        alertView.tag=2525;
        [alertView show];
     }
}


-(void)alertView:(UIAlertView *)alertView 
     clickedButtonAtIndex:(NSInteger)buttonIndex  {

   if(alertView.tag==2525)  {
      [UIApplication sharedApplication].applicationIconBadgeNumber =
      [UIApplication sharedApplication].applicationIconBadgeNumber-1;
   }
}
-1
source share
2 answers

You must do this from the server side. In my case, I did this through php and mysql. Here is my database enter image description here

badgecount , push

        $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); 
        ...

api badgcount 0,

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

, , .

+2

, :

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

1 , . . , 1, , 1 .

, . push-, , .

+1

All Articles