import SwiftUI import UIKit import UserNotifications class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject, UNUserNotificationCenterDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { UNUserNotificationCenter.current().delegate = self application.registerForRemoteNotifications() return true } func application( _: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) { debug(.remoteControl, "Received notification") Task { await TrioRemoteControl.shared.handleRemoteNotification(userInfo: userInfo) completionHandler(.newData) } } func application( _: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) } let token = tokenParts.joined() Task { await TrioRemoteControl.shared.handleAPNSChanges(deviceToken: token) } } func application( _: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error ) { debug(.remoteControl, "Failed to register for remote notifications: \(error.localizedDescription)") } }