如何清除 iOS 中的推送通知徽章计数?

问题描述:

我想在应用启动后清除推送通知徽章计数.我不知道在哪里设置下面的代码.请简要说明清除徽章计数.

I want to clear the push notification badge count once app is launched.Im not clear where to set the below code.Please give brief description about clearing the badge count.

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

你应该这样设置:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

在如果应用程序启动并发送到后台,那么这些 AppDelegate 方法中的任何一个都不会被调用 didFinishLaunchingWithOptions 方法,因此请使用以下任一方法:

in either of these AppDelegate methods if the application is launched and sent to background then you launch the application didFinishLaunchingWithOptions method will not be called so use either of these methods:

- (void)applicationWillEnterForeground:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application

适用于 Swift 3+

For Swift 3+

- func applicationWillEnterForeground(_ application: UIApplication)
- func applicationDidBecomeActive(_ application: UIApplication)