0

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

4

1 回答 1

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)
}
于 2017-01-05T09:01:46.220 回答