如何清除 iOS 中的推送通知徽章计数? [英] How to clear push notification badge count in iOS?

查看:30
本文介绍了如何清除 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)

这篇关于如何清除 iOS 中的推送通知徽章计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆