#if os(iOS) import UIKit /// The iPhone app's delegate: APNs hands the device token here, and the /// notification centre and Live Activities are set up before the first /// screen, so a tap that launched the app, or an activity the server /// started while it was closed, is not missed. @MainActor public final class EquipoPhoneDelegate: NSObject, UIApplicationDelegate { public let notifications = SystemNotifications() public private(set) lazy var model = EquipoAppModel(notifications: notifications) public func application(_ application: UIApplication, didFinishLaunchingWithOptions options: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { #if DEBUG && targetEnvironment(simulator) if ProcessInfo.processInfo.environment["EQUIPO_NOTIFICATION_FIXTURE"] != nil || ProcessInfo.processInfo.environment["EQUIPO_SHARE_FIXTURE"] != nil || ProcessInfo.processInfo.environment["EQUIPO_SCREENSHOT_FIXTURE"] != nil { return true } #endif notifications.onResponse = { [weak self] response in self?.model.notificationResponse(response) } notifications.onRoute = { [weak self] route in self?.model.open(route) } model.liveActivities.start() // A push can launch the app without creating a view. Validate the // shared identity and attach its device before sending activity tokens. Task { await model.start() } return true } public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { let push = model.push Task { await push.deviceTokenChanged(deviceToken) } } /// No token (no network, or a build that cannot receive pushes): the /// app works as before, and asks again at the next launch. public func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {} } #endif