Screaming-Reminder/Screaming Reminder/Utils/NotificationsUtils.swift
2024-07-30 14:45:07 +02:00

36 lines
1.1 KiB
Swift

//
// NotificationsUtils.swift
// Screaming Reminder
//
// Created by Amine Bou on 12/07/2024.
//
import Foundation
import SwiftUI
import SwiftData
func scheduleNotifications(reminder: Reminder) {
let notification = Notification(reminder: reminder)
notification.triggers.forEach {
let content = UNMutableNotificationContent()
content.title = notification.reminder.label
content.sound = UNNotificationSound.defaultCritical
content.categoryIdentifier = "CAT"
let request = UNNotificationRequest(identifier: getIdentifier(reminder: reminder, trigger: $0), content: content, trigger: $0)
// add our reminder request
UNUserNotificationCenter.current().add(request)
}
}
func cancelNotifications(reminder: Reminder) {
let identifiers = getTriggersForReminder(reminder: reminder).map {
getIdentifier(reminder: reminder, trigger: $0)
}
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: identifiers)
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers)
}