import UIKit @main final class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { Badge.registerBackgroundRefresh() return true } } /// The one window. iOS will not run an app that has not adopted scenes, and a CarPlay app would /// be a second scene beside this one. final class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options: UIScene.ConnectionOptions) { guard let scene = scene as? UIWindowScene else { return } let window = UIWindow(windowScene: scene) window.rootViewController = WebViewController() window.makeKeyAndVisible() self.window = window } /// iOS wants the request made as the app leaves, with the user's last look at the list; the /// one made on coming forward stays for a run that was cut short. func sceneDidEnterBackground(_ scene: UIScene) { Badge.scheduleBackgroundRefresh() } func sceneDidBecomeActive(_ scene: UIScene) { Badge.requestPermission() Badge.scheduleBackgroundRefresh() Task { await Badge.refresh() } } }