I've tried to create a badge updater for local notifications using the UserNotifications.framework
. And here's my code
func badgeUpdate() {
let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests { (requests) in
let number = NSNumber(integerLiteral: +1)
if requests.count != 0 {
center.removeAllPendingNotificationRequests()
for request in requests {
request.content.badge = number
center.add(request, withCompletionHandler: { (error) in
})
}
}
}
}
This is an error line:
request.content.badge = number
And gives me an error like so: Cannot assign to property: 'badge' is a get-only property
How to fix that? Thanks a lot.
Inspired by this link iPhone: Incrementing the application badge through a local notification