3

Problem:

  • Let say I get 3 notification.
  • It shows the badge count 3 on my app icon.
  • I open the app or click on the notification and it clears the badge (All Good so far)
  • Now when I get a new notification, the badge count shown on my app icon is 4 instead of 1
  • That means that the badge count was not reset on Urbanairship end

My Code so far:

-(void)resetBadgeNotifications:(UIApplication *)application using:(NSDictionary *)notificationInfo{
    if( notificationInfo != nil ){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"newNotification" object:notificationInfo];
    }
    application.applicationIconBadgeNumber=1;
    application.applicationIconBadgeNumber=0;
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    [application cancelAllLocalNotifications];
    [[UAPush shared] setBadgeNumber:1];//set to 1
    [[UAPush shared] resetBadge];//zero badge
}

I am calling this method from the following three places:

didFinishLaunchingWithOptions

didRegisterForRemoteNotificationsWithDeviceToken

applicationDidBecomeActive

In the last line of my function, I am clearly resetting the badge on UrbanAirship. But it seems to be not working. Can anyone please correct me if I am missing something?

Adil Malik
  • 6,279
  • 7
  • 48
  • 77
  • I have the same problem, do you find out the solution? My workaround is to always set badget to 1 when pushing via airship. – Bruce Tsai Jul 11 '14 at 09:11

1 Answers1

1

My original answer was for the basic push notifications offered by APNS. I wasn't aware that UrbanAirship have a mechanism to track the badge number for each token. Reading their documentation, it's possible that you forgot to call:

[[UAPush shared] setAutobadgeEnabled:YES]

If your application uses Urban Airship’s autobadge feature, enable client-side autobadge tracking in application:didFinishLaunchingWithOptions: before changing the badge value:

[[UAPush shared] setAutobadgeEnabled:YES]; [[UAPush shared] resetBadge];//zero badge

Eran
  • 387,369
  • 54
  • 702
  • 768
  • You mean my server should keep unread count for all the users and when a user opens the app of clicks on a notification I should reset the notification on my server, so that next time it sends from 1 again? – Adil Malik Nov 19 '13 at 15:20
  • If that's true, what does UA's `resetBadge` method do? – Adil Malik Nov 19 '13 at 15:22
  • @AdilMalik My mistake. I wasn't aware of the auto badge functionality on UA. See my updated answer. – Eran Nov 19 '13 at 15:54
  • thanks for investigating. But I am doing the same, still no it's not working. – Adil Malik Nov 19 '13 at 16:17