问题
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