I can add a badge to the AppIcon, I just cannot remove it.
I have a notification helper class, with a refresh badge number function, as shown below:
import UserNotifications
class NotificationHelper {
...
//fetch all notifications, and update the tabBarController
func refreshTabBarBadge(tabBarController: UITabBarController) {
... some Core Data related stuff to set badge
let content = UNMutableNotificationContent()
if badge > 0 {
content.badge = badge as NSNumber
}
else {
content.badge = 0
content.badge = nil
}
print("set app icon badge to: \(badge)")
}
When I print the output, I see:
set app icon badge to: 1
This sets a badge on the AppIcon.
Then when I trigger an event that causes the badge
variable to decrease I see:
set app icon badge to: 0
Yet, when I background the app and check the icon, the badge remains, set to 1.
Its as if content.badge
is not working at all. In the Apple documentation it says if the badge number is 0, it will remove the badge, but this is not the case. As you can see, I also try setting it to nil
afterwards.
How do I remove the badge from the AppIcon?
set badge number = 0.
like UIApplication.shared.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