Is there any way to remove all remote notifications that are one day old?
Asked
Active
Viewed 79 times
1 Answers
0
Try this,
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
let yesterday = NSCalendar.current.date(byAdding: .day, value: -1, to: Date())!
let identifiersToRemove = notifications
.filter { $0.date.compare(yesterday) == .orderedAscending }
.map { $0.request.identifier }
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiersToRemove)
}

nRewik
- 8,958
- 4
- 23
- 30