有没有办法删除一天前的所有远程通知?

时间:2017-01-04 19:33:33

标签: ios swift remote-notifications

有没有办法删除一天之前的所有远程通知?

1 个答案:

答案 0 :(得分:0)

试试这个,

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)
}