0

Is there any way to remove all remote notifications that are one day old?

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
Sadiq Khoja
  • 522
  • 1
  • 5
  • 23

1 Answers1

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