I am using userNotification framework in my app and I want to set the badge to the number of notification received so what I did was to set the number of notification received into a userdefaults then i tried to assign the value to the badge to get me a badge number but the badge number would not increase. This is my code below
To set value of received notification
center.getDeliveredNotifications { (notification) in
UserDefaults.standard.set(notification.count, forKey: Constants.NOTIFICATION_COUNT)
print("notification.count \(notification.count)")
print(".count noti \(UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))")
}
this accurately prints the number of notification recieved and when i decided to set it to my badge it only shows 1
content.badge = NSNumber(value: UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))
I have no idea why the value does not increase every time. any help would be appreciated.
or if it is possible to always update the badge anywhere in the app
from Usernotification framework badge does not increase
No comments:
Post a Comment