您可以在任何地方进行设置。例如:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:123]; // this one
}
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:[UIApplication sharedApplication].applicationIconBadgeNumber+1];
- tuledevapplication:didReceiveRemoteNotification:
`(NSDictionary *)userInfo`
使用该函数更新应用程序图标徽章计数
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:@"aps"] objectForKey: @"badgecount"] intValue];
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9
}
}
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:22];
http://www.touch-code-magazine.com/how-to-add-a-badge-to-the-application-icon/
UIApplication.shared.applicationIconBadgeNumber = <Int_count>