要在应用程序变为活动状态时清除徽章计数,请使用委托方法
调用[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];在applicationWillEnterForeground或applicationDidBecomeActive中
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
要么
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
迅速
func applicationWillEnterForeground(application: UIApplication) {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
要么
func applicationDidBecomeActive(application: UIApplication) {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
对于Swift 3:
UIApplication.shared.applicationIconBadgeNumber = 0