Reset urbanairship badge count

五迷三道 提交于 2020-01-02 07:45:09

问题


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?


回答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



来源:https://stackoverflow.com/questions/20073212/reset-urbanairship-badge-count

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