Screaming-Reminder/Screaming Reminder/Utils/NotificationDelegate.swift
2024-07-30 14:42:42 +02:00

45 lines
1.4 KiB
Swift

//
// NotificationDelegate.swift
// Screaming Reminder
//
// Created by Amine Bou on 12/07/2024.
//
import Foundation
import SwiftUI
import SwiftData
class NotificationDelegate: NSObject , UNUserNotificationCenterDelegate{
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler:
@escaping () -> Void) {
let title = response.notification.request.content.title
switch response.actionIdentifier {
case "DONE_ACTION":
let content = UNMutableNotificationContent()
content.title = "Bravo !"
content.subtitle = "Tu as fais ce que tu devais faire ! (Il faudra ignorer les autres notifications 😅)"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)
// choose a random identifier
let request = UNNotificationRequest(identifier: "\(title)-done", content: content, trigger: trigger)
// add our reminder request
UNUserNotificationCenter.current().add(request)
break
default:
exit(0)
break
}
// Always call the completion handler when done.
completionHandler()
}
}