简体   繁体   English

推送通知徽章重置计数

[英]Push notification badge reset count

I'm using PushBot as my push notification service, my issue is how do I reset the badge count. 我正在使用PushBot作为我的推送通知服务,我的问题是如何重置徽章计数。 I've search and read to use this line of code: 我搜索并阅读使用这行代码:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

The only way the badge count gets reset is if I quit the app from running on the mulit-task bar and launch the app again, any help is greatly appreciated. 重置徽章计数的唯一方法是,如果我退出应用程序,在多个任务栏上运行并再次启动应用程序,我们非常感谢任何帮助。 Thanks, 谢谢,

Just make a button on your UI and on his action put the code line: 只需在您的UI上创建一个按钮,然后在他的操作上放置代码行:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

It will reset it. 它会重置它。

Take a look Here for some other implementations. 看看这里的其他一些实现。

To clear the badge count whenever the application becomes active, simply include your line of code: 要在应用程序变为活动状态时清除徽章计数,只需包含您的代码行:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

In the AppDelegate.m file's applicationDidBecomeActive delegate method. AppDelegate.m文件的applicationDidBecomeActive委托方法中。

applicationDidFinishLaunchingWithOptions is only called on the initial launch, and does not get called again when the application goes to the background and back to the foreground. applicationDidFinishLaunchingWithOptions仅在初始启动时调用,并且在应用程序转到后台并返回到前台时不会再次调用。

For Swift 3.0 对于Swift 3.0

//AppleDelgate.swift
 func applicationDidBecomeActive(_ application: UIApplication) {
        //....
        application.applicationIconBadgeNumber = 0
       //....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM