Screaming-Reminder/Screaming Reminder/Screaming_ReminderApp.swift

65 lines
1.8 KiB
Swift
Raw Permalink Normal View History

2024-07-11 10:38:11 +00:00
//
// 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)
}
}
}
}