Yayo Yayo - 2 years ago 186
iOS Question

UNUserNotificationCenter not clean notification of icon app in swift 3?

I have a problem. I had a notification in my app. Im trying this. But now, i can't delete from the icon app.

I run this code:

UNUserNotificationCenter.current().getPendingNotificationRequests(completionHandler: {requests -> () in
print("\(requests.count) requests -------")
for request in requests{
print(request.identifier)
}

UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
})

UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: {deliveredNotifications -> () in
print("\(deliveredNotifications.count) Delivered notifications-------")
for notification in deliveredNotifications{
print(notification.request.identifier)
}

UNUserNotificationCenter.current().removeAllDeliveredNotifications()
})


And trace is this:

0 requests -------
0 Delivered notifications-------

In the icon app, i see this:

Im can't up image :( but in this, i see a number one on the icon app and red foreground

Answer Source

Yayo you need to set badge count to 0 for removing badge count from your app icon. For that -

UIApplication.shared.applicationIconBadgeNumber = 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download