migration
This commit is contained in:
63
PediFoods/PediFoodsApp.swift
Normal file
63
PediFoods/PediFoodsApp.swift
Normal file
@@ -0,0 +1,63 @@
|
||||
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])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user