We have developed an ios app using phonegap and have implemented push notification functionality in our app. Push notification works perfectly fine for us. We have configured push notification for both (alerts and badge) and both works fine. When we click on the alert list it redirects us to the application and clears all the notifications from the alert list and also the badge counter is set to 0.
But when we click on the application icon(badge counter) it brings app to the foreground but the badge counter and alerts are not getting cleared.
We have used following code in didFinishLaunchingWithOptions method (in appdelegate.m file)that clears out the alerts and resets the badge only on-click of alerts
application.applicationIconBadgeNumber = 0;
can anyone provide us the solution that shows same behaviour when we click on app icon with badge counter.
Tap the "Badge App Icon" button to toggle it from "On" to "Off." Alternatively, if you don't want any notifications for that app, tap the "Notification Center" button at the top of the screen to turn it off instead. When you click the "Home" button, the badge is removed from the app's icon.
Tap the "Settings" icon on the iPhone's home screen and then tap "Notifications." Scroll down through the list of apps in the Notification Section and select the app you want disabled from using badge alerts. The notifications used by that app are displayed beneath its name, such as "Badges," "Alerts" and "Banners."
Launch the app that is displaying an alert by tapping its icon on the iPhone's home screen. In some cases, this is sufficient to clear the badge. For example, if there is a red circle with a number on the Messages icon, it indicates that you have new text messages. Launching the Messages app and closing it again erases the icon's red badge.
If there is a badge on the "Voicemail" button, you need to tap that button and listen to the message to clear that badge. In the case of an iOS update, you'll have to install the update to clear that badge. When you go back to the home screen, the badge is removed from the app's icon.
To clear the badge count whenever the application becomes active use delegate
method. You can use UIApplicationDelegate
in AppDelegate.
call the [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; in either applicationWillEnterForeground nor applicationDidBecomeActive
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
or
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
Swift
func applicationWillEnterForeground(application: UIApplication) {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
or
func applicationDidBecomeActive(application: UIApplication) {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
For Swift 3:
UIApplication.shared.applicationIconBadgeNumber = 0
iOS 13 >
func sceneDidBecomeActive(_ scene: UIScene) {
UIApplication.shared.applicationIconBadgeNumber = 0
}
If you are on iOS 13 supporting multiple windows, do the same on the method Scene Became active like this. This method is on SceneDelegate.
func sceneDidBecomeActive(_ scene: UIScene) {
UIApplication.shared.applicationIconBadgeNumber = 0;
}
In Swift the following works to put in func applicationWillEnterForeground(application: UIApplication)
:
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With