So, I'm running a loop that basically sets 50 notifications at a time. In the loop, I set the content,
let content = self.notificationContent(title: "my title", body: "whatever else I want to say")
content.threadIdentifier = "my.thread"
content.categoryIdentifier = "my.category"
content.badge = self.counter as NSNumber // -- this counter gets incremented for each iteration of the loop
//.. Calendar trigger
var dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: myTime)
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
let identifier = "message.notify.reset\(self.notifyNumber)"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
//.. Add it to notification center
UNUserNotificationCenter.current().add(request) { (error) in
self.printError(error, location: "*** Add request for identifier: " + identifier)
}
Then, once that one is added, I increment the counter and add the next one. It does all of this correctly but it's not really what I want to happen because once the notifications are set, it's basically out of my App... and whichever one triggers next, is the number that shows up for the badge. So, for example, if number 48 is the one that gets sent at 8pm, the badge now says 48 regardless of whether or not the user "cleared" any/all of the other notifications prior to that.
What I would like to see happen somehow is for the notification manager to recognize that when a new notification is delivered, it needs to look at the previous count for the badge number and then increment that by 1. So, if it was previously 7 for the badge number, it should be 8 after the next notification is delivered. Maybe it's me, but this seems kind of obvious/basic that that's the way it should work. Am I missing something? Is there a way to do this?
Topic:
Programming Languages
SubTopic:
Swift
Tags: