1

I am working on remote push notification and getting badge count in payload. it's working fine when my app is active(foreground) but when app run in background and i got push then badge count not increases. Please help.

when app is active it calls didReceiveNotification method.

I am receiving this type of info in payload.

{aps = {alert = "Hi all.";badge = 6;sound = default;};}

I am not sure where is issue.

Gilad Green
  • 36,708
  • 7
  • 61
  • 95
Ga Ne Sh
  • 59
  • 9
  • Have you tried setting [UIApplication sharedApplication].applicationIconBadgeNumber = xx, in -applicationWillEnterForeground: or -applicationDidBecomeActive: And one more thing it will not increase, normally badge count maintained at servers you can update badge value in code by using [UIApplication sharedApplication].applicationIconBadgeNumber = xx – Aditya Deshmane Oct 30 '13 at 20:15
  • Hi Thanks for quick response. i am doing following code in didReceiveRemoteNotification. int badgeCount = [[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue]; [UIApplication sharedApplication].applicationIconBadgeNumber = badgeCount; Please can you tell me what to do with this. I am confused because every one says that it will autoincreament by os according to APNS server response. – Ga Ne Sh Oct 31 '13 at 04:56
  • 1
    Hi Thanks all I got the issue. It is from server side. actually badge should be an integer value. but due to unknown reason it is considering as a string. – Ga Ne Sh Oct 31 '13 at 06:23
  • Hi you can check this ans http://stackoverflow.com/a/23948633/2246798 – souvickcse May 30 '14 at 06:49
  • I received push notification in all state i.e. when app is in forground, background, close(terminated)..! but my problem is that how to increment badge count when app is in background state and close (terminate) state???? Please tell me in details how i do it....? my app badge count is only increase when app is in forground state.....? if possible please tell me in brief.......!SWIFT 3 – Kiran Jadhav Jul 29 '17 at 05:05
  • Badge count is come from backend. So you need to keep count of badge in backend. When you open the app you have to set it 0 and with API call it will be reset in backend and start from 0 again. There is a payload format your backend dev use to send badge. – Ga Ne Sh Jul 31 '17 at 07:55

1 Answers1

0

Try this

-(void)applicationDidBecomeActive:(UIApplication *)application
{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    [[UIApplication sharedApplication] cancelAllNotifications];
}
Kevin Cittadini
  • 1,449
  • 1
  • 21
  • 30
irna
  • 21
  • 2