AppDelegate.swift 945 B

123456789101112131415161718192021222324252627282930
  1. import SwiftUI
  2. import UIKit
  3. import UserNotifications
  4. class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject {
  5. @Published var notificationAction: NotificationAction? = nil
  6. func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
  7. UNUserNotificationCenter.current().delegate = self
  8. return true
  9. }
  10. }
  11. extension AppDelegate: UNUserNotificationCenterDelegate {
  12. func userNotificationCenter(
  13. _: UNUserNotificationCenter,
  14. didReceive response: UNNotificationResponse,
  15. withCompletionHandler completionHandler: @escaping () -> Void
  16. ) {
  17. if let action = response.notification.request.content.userInfo["action"] as? String {
  18. notificationAction = NotificationAction(rawValue: action)
  19. }
  20. completionHandler()
  21. }
  22. }
  23. enum NotificationAction: String {
  24. case snoozeAlert = "snooze"
  25. }