Files
Kisani/App/AppDelegate.swift

35 lines
1.1 KiB
Swift
Raw Normal View History

import UIKit
import BackgroundTasks
import UserNotifications
final class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
BackgroundTaskManager.registerTasks()
requestNotificationPermission()
setupLANMonitor()
return true
}
private func requestNotificationPermission() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { _, _ in }
}
private func setupLANMonitor() {
let monitor = LANMonitor.shared
monitor.onTrustedNetworkJoined = { ssid in
let store = ConnectionStore.shared
guard store.lanTriggerEnabled, !store.isInQuietHours else { return }
let delay = TimeInterval(store.startDelaySeconds)
BackgroundTaskManager.scheduleBackup(delay: delay)
}
monitor.start()
}
func applicationDidEnterBackground(_ application: UIApplication) {
BackgroundTaskManager.scheduleAppRefresh()
}
}