I'm currently writing an alarm application, which should be sending infinite local notifications if app is terminated. Similar logic is implemented in Alarmy app.
Local push notifications count is restricted to 64, which means we probably should use repeating option like this.
func setNotification(date: Date, ringtoneName: String, repeatWeekdays: [Int], snoozeEnabled: Bool, onSnooze: Bool, uuid: String, sleepMoreMinit: Int) {
let datesForNotification = getNotificationDates(baseDate: date, onWeekdaysForNotify: repeatWeekdays)
let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Alarm"
notificationContent.body = "Wake Up"
for date in datesForNotification {
var dateComponents = Calendar.current.dateComponents([.weekday,.hour,.minute, .second], from: date)
for i in 0..<60 {
dateComponents.second = (dateComponents.second ?? 0) + 1
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest(identifier: "\(date)",
content: notificationContent,
trigger: trigger)
UNUserNotificationCenter.current().add(request) { _ in }
}
}
}
But the thing is local notifications can be repeated only once per minute, so I don't understand how Alarmy sends infinite notifications each second. Is there any solution for this case?