0

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

Community
  • 1
  • 1
Mannopson
  • 2,634
  • 1
  • 16
  • 32
  • 1
    Are you trying to do this? `UIApplication.shared.applicationIconBadgeNumber = number`? That's how you set the app's badge number. You're trying to change the badge number the actual request is sending you, which is read-only. – Pierce Jan 28 '17 at 02:42
  • Does not work. I want create an auto updater like the iOS Reminders app while my app is inactive state. I mean badges – Mannopson Jan 28 '17 at 02:51

0 Answers0