Вы должны использовать NSCalendarNotifiationTrigger
Пример для вас
var date = Date()
let notificationCenter = UNUserNotificationCenter.current()
for i in 0...10 {
let content = UNMutableNotificationContent()
content.title = "Title\(i)"
content.body = "Body"
var dateComponents = DateComponents()
dateComponents.calendar = Calendar.current
let secondsToAdd = 5
dateComponents.second = secondsToAdd
guard let futureDate = dateComponents.calendar?.date(byAdding: dateComponents, to: date),
let futureDateComponents = dateComponents.calendar?.dateComponents([.day, .hour, .minute, .second], from: futureDate) else { return }
date = futureDate
print(futureDate)
// Create the trigger as a repeating event.
let trigger = UNCalendarNotificationTrigger(
dateMatching: futureDateComponents, repeats: false)
// Create the request
let notificationIdentifier = "notification\(i)seconds" // you can use this indentifier if you want to cancel a notification
let request = UNNotificationRequest(identifier: notificationIdentifier,
content: content, trigger: trigger)
// Schedule the request with the system.
notificationCenter.add(request) { (error) in
if error != nil {
// Handle any errors.
}
}
}
, где secondsToAdd равно 5, поэтому он рассчитывает предстоящую дату
Выше кода будет размещать 10 уведомлений с интервалом в 5 секунд
Вам необходимо рассчитать максимальное время (последняя запись даты) и расписание уведомлений, используя вышеуказанный код