import OSLog import SwiftUI let logger: Logger = Logger(subsystem: "com.br.pedifoods.app", category: "PediFoods") @main struct PediFoodsApp: App { @UIApplicationDelegateAdaptor(PediFoodsAppDelegate.self) private var appDelegate @Environment(\.scenePhase) private var scenePhase var body: some Scene { WindowGroup { ContentView() } .onChange(of: scenePhase) { oldPhase, newPhase in switch newPhase { case .active: logger.debug("onResume") NotificationCenter.default.post(name: .appDidResume, object: nil) case .inactive: logger.debug("onPause") case .background: logger.debug("onStop") @unknown default: logger.debug("unknown scene phase: \(String(describing: newPhase))") } } } } final class PediFoodsAppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { logger.debug("onInit") return true } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { logger.debug("onLaunch") Task { @MainActor in PushNotificationCoordinator.shared.startObservingDeviceToken() PushNotificationCoordinator.shared.becomeNotificationCenterDelegate() await PushNotificationCoordinator.shared.refreshRegistrationIfAuthorized() await PushNotificationCoordinator.shared.syncCustomerAttributes() } return true } func applicationWillTerminate(_ application: UIApplication) { logger.debug("onDestroy") } func applicationDidReceiveMemoryWarning(_ application: UIApplication) { logger.debug("onLowMemory") } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { NotificationCenter.default.post(name: NSNotification.Name("didRegisterForRemoteNotificationsWithDeviceToken"), object: application, userInfo: ["deviceToken": deviceToken]) } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: any Error) { NotificationCenter.default.post(name: NSNotification.Name("didFailToRegisterForRemoteNotificationsWithError"), object: application, userInfo: ["error": error]) } }