Notifications and UI color scheme update

This commit is contained in:
maddiebaka
2023-06-07 15:47:26 -04:00
parent a894876623
commit 90be4321b0
6 changed files with 100 additions and 14 deletions

View File

@@ -0,0 +1,42 @@
//
// UserNotificationProtocol.swift
// Soyuz
//
// Created by Madeline Pace on 5/28/23.
//
import UserNotifications
class UserNotificationHandler {
static var shared = UserNotificationHandler()
private var center = UNUserNotificationCenter.current()
enum NotificationType {
case printComplete
}
private init() {
center.requestAuthorization(options: [.alert, .sound, .badge, .provisional]) { granted, error in
if let error = error {
print("Error requesting authorization: \(error)")
}
}
}
func sendNotification(_ type: NotificationType) {
print("Sending notification.")
// Build notification request
let content = UNMutableNotificationContent()
// TODO: Replace this with localized strings
content.title = "Print Complete! 🎉"
let request = UNNotificationRequest(identifier: "Print Finished", content: content, trigger: nil)
// Dispatch notification to system
center.add(request) { (error: Error?) in
if let theError = error {
print("Error: \(theError)")
}
}
}
}