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.
我想要清除推送通知徽章计数一旦app启动。我不清楚在哪里设置下面的代码。请简要说明清除徽章的数量。
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
5 个解决方案
#1
62
You should set this:
你应该设置这个:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[UIApplication sharedApplication]。applicationIconBadgeNumber = 0;
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:
在这些AppDelegate方法中如果应用程序被启动并被发送到后台那么你就会启动应用didFinishLaunchingWithOptions方法将不会被调用所以使用这两种方法:
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
For Swift 3+
为迅速3 +
- func applicationWillEnterForeground(_ application: UIApplication)
- func applicationDidBecomeActive(_ application: UIApplication)
#2
4
in swift 3+
在斯威夫特3 +
in your AppDelegate.Swift , when your application active clear all like below.
在你AppDelegate。Swift,当您的应用活动清除如下。
func applicationDidBecomeActive(_ application: UIApplication) {
UIApplication.shared.applicationIconBadgeNumber = 0
}
#3
1
You can set that code anywhere in code.. Does not matter. But generally, is kept in UIApplicationDidFinishLaunching
..
你可以在代码的任何地方设置那个代码。无关紧要。但通常是保存在UIApplicationDidFinishLaunching。
#4
1
Well, the better way to do this is to make a function that subtract the badge number then make a UIButton to let the user to clear the badge. In the default mail application, if you read one email the badge will subtract one from the icon. You should never set it 0 at launch or resume, it is meaningless and make the app look crappy. Subtract it when the user interact with that event is the best way to do it. Make your app more professional, if you just reset it when the app launch who know what is the bedges mean, may as well not use it.
更好的方法是做一个函数减去徽章编号然后制作一个UIButton让用户清除徽章。在默认的邮件应用程序中,如果你读了一封电子邮件,徽章就会从图标中减去一个。你不应该在启动或恢复时设置为0,这毫无意义,会让应用程序看起来很糟糕。当用户与事件交互时减去它是最好的方式。让你的应用更专业,如果你只是在应用启动时重置它谁知道什么是bedges,可能还不如不使用它。
#5
0
UIApplication.shared.applicationIconBadgeNumber = 1
UIApplication.shared.applicationIconBadgeNumber = 0
#1
62
You should set this:
你应该设置这个:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[UIApplication sharedApplication]。applicationIconBadgeNumber = 0;
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:
在这些AppDelegate方法中如果应用程序被启动并被发送到后台那么你就会启动应用didFinishLaunchingWithOptions方法将不会被调用所以使用这两种方法:
- (void)applicationWillEnterForeground:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application
For Swift 3+
为迅速3 +
- func applicationWillEnterForeground(_ application: UIApplication)
- func applicationDidBecomeActive(_ application: UIApplication)
#2
4
in swift 3+
在斯威夫特3 +
in your AppDelegate.Swift , when your application active clear all like below.
在你AppDelegate。Swift,当您的应用活动清除如下。
func applicationDidBecomeActive(_ application: UIApplication) {
UIApplication.shared.applicationIconBadgeNumber = 0
}
#3
1
You can set that code anywhere in code.. Does not matter. But generally, is kept in UIApplicationDidFinishLaunching
..
你可以在代码的任何地方设置那个代码。无关紧要。但通常是保存在UIApplicationDidFinishLaunching。
#4
1
Well, the better way to do this is to make a function that subtract the badge number then make a UIButton to let the user to clear the badge. In the default mail application, if you read one email the badge will subtract one from the icon. You should never set it 0 at launch or resume, it is meaningless and make the app look crappy. Subtract it when the user interact with that event is the best way to do it. Make your app more professional, if you just reset it when the app launch who know what is the bedges mean, may as well not use it.
更好的方法是做一个函数减去徽章编号然后制作一个UIButton让用户清除徽章。在默认的邮件应用程序中,如果你读了一封电子邮件,徽章就会从图标中减去一个。你不应该在启动或恢复时设置为0,这毫无意义,会让应用程序看起来很糟糕。当用户与事件交互时减去它是最好的方式。让你的应用更专业,如果你只是在应用启动时重置它谁知道什么是bedges,可能还不如不使用它。
#5
0
UIApplication.shared.applicationIconBadgeNumber = 1
UIApplication.shared.applicationIconBadgeNumber = 0