Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / FindFamily / FindFamilyiOS / App / AppDelegate.swift
AppDelegate.swift32 lines · 1.3 KiBRaw
| 1 | import SwiftUI |
| 2 | import UIKit |
| 3 | import CoreLocation |
| 4 | import UserNotifications |
| 5 | |
| 6 | final 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 | // Subscribe to sharing-state changes first so a toggle that fires |
| 23 | // before the DB finishes loading is still picked up, then start |
| 24 | // location work only when we're actually sharing with someone — |
| 25 | // this is the iOS analog of LocationTrackingService on Android. |
| 26 | // The same gate runs on background relaunch from location events. |
| 27 | LocationsHandler.shared.beginMonitoringSharing() |
| 28 | LocationsHandler.shared.startLocationUpdatesIfSharing() |
| 29 | } |
| 30 | return true |
| 31 | } |
| 32 | } |