Build 5. The badge's refresh was requested only when the app came forward; iOS asks for it as the app goes to the background. The request made on coming forward stays. The timing is still iOS's. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
38 lines
1.3 KiB
Swift
38 lines
1.3 KiB
Swift
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() }
|
|
}
|
|
}
|