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

65 lines
1.8 KiB
Swift

//
// Screaming_ReminderApp.swift
// Screaming Reminder
//
// Created by Amine Bou on 11/07/2024.
//
import SwiftUI
import SwiftData
@main
struct Screaming_ReminderApp: App {
private var notificDelegate : NotificationDelegate = NotificationDelegate()
let modelContainer: ModelContainer
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(modelContainer)
}
init() {
do {
let schema = Schema([
Reminder.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
modelContainer = try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
registerForNotification()
// Define the custom actions.
let doneAction = UNNotificationAction(identifier: "DONE_ACTION",
title: "Fait !",
options: [])
let notificationCategory =
UNNotificationCategory(identifier: "CAT",
actions: [doneAction],
intentIdentifiers: [],
hiddenPreviewsBodyPlaceholder: "",
options: .customDismissAction)
// Register the reminder type.
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.setNotificationCategories([notificationCategory])
UNUserNotificationCenter.current().delegate = notificDelegate
}
func registerForNotification() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in
if success {
} else {
exit(0)
}
}
}
}