当我注册新通知-UIApplication.shared.applicationIconBadgeNumber-始终为0时,这就是为什么我的徽章中始终为“ 1”的原因。如何在本地通知中更新它?
let content = UNMutableNotificationContent()
let notificationInterval = components(forDay: settings.object.timeInterval)
let requestIdentifier = settings.object.identifier
content.badge = Swift.min(notificationsCount, UIApplication.shared.applicationIconBadgeNumber + 1) as NSNumber
content.body = settings.object.body
content.title = settings.object.title
content.categoryIdentifier = "categoryIdentifier"
content.sound = UNNotificationSound.default()
content.setValue(true, forKey: "shouldAlwaysAlertWhileAppIsForeground")
let trigger = UNCalendarNotificationTrigger(dateMatching: notificationInterval, repeats: true)
let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [request.identifier])
UNUserNotificationCenter.current().add(request) { error in
if error != nil {
print(error?.localizedDescription ?? "Notification error")
}
print("Notification Register Success")
}