Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / apple / FindFamily / FindFamilyiOS / App / AppDelegate.swift

AppDelegate.swift35 lines · 1.5 KiBRaw
1import SwiftUI
2import UIKit
3import CoreLocation
4import UserNotifications
5
6final class AppDelegate: NSObject, UIApplicationDelegate {
7 var isLaunchedFromLocationEvent = false
8
9 func application(
10 _ application: UIApplication,
11 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
12 ) -> Bool {
13 isLaunchedFromLocationEvent = launchOptions?[.location] != nil
14 UIDevice.current.isBatteryMonitoringEnabled = true
15
16 // Request notification permission early (best-effort).
17 UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { _, _ in }
18
19 Task { @MainActor in
20 // Kick off the network / identity layer.
21 await Networking.shared.start()
22 // One long-lived relay socket: connects now if we're in the foreground and
23 // whenever the app becomes active (tracking and location wakes also start it).
24 RelaySocket.shared.beginLifecycle()
25 // Subscribe to sharing-state changes first so a toggle that fires
26 // before the DB finishes loading is still picked up, then start
27 // location work only when we're actually sharing with someone —
28 // this is the iOS analog of LocationTrackingService on Android.
29 // The same gate runs on background relaunch from location events.
30 LocationsHandler.shared.beginMonitoringSharing()
31 LocationsHandler.shared.startLocationUpdatesIfSharing()
32 }
33 return true
34 }
35}