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?
设置徽章编号= 0.像UIApplication.shared.applicationIconBadgeNumber = 0
I've used
content.badge = -1
to remove the badge.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.