oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

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