From 357852fbd946a815b8a7d264236f96880935e6cf Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 19 Feb 2026 15:05:23 +0100 Subject: [PATCH] Fix BGTaskScheduler crash by moving registration to App.init() Apple requires BGTaskScheduler.register() to be called during the app launch sequence before the run loop starts. Moving it from .onAppear (too late) to init() prevents the crash on TestFlight builds. --- Yattee/YatteeApp.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Yattee/YatteeApp.swift b/Yattee/YatteeApp.swift index e4d91533..eab00fc2 100644 --- a/Yattee/YatteeApp.swift +++ b/Yattee/YatteeApp.swift @@ -50,6 +50,10 @@ struct YatteeApp: App { init() { // Configure Nuke image loading pipeline ImageLoadingService.shared.configure() + + // Register background tasks early — Apple requires BGTaskScheduler.register() + // to be called during the app launch sequence, before the run loop starts. + appEnvironment.backgroundRefreshManager.registerBackgroundTasks() } var body: some Scene { @@ -253,9 +257,6 @@ struct YatteeApp: App { guard !backgroundTasksRegistered else { return } backgroundTasksRegistered = true - // Register background tasks - appEnvironment.backgroundRefreshManager.registerBackgroundTasks() - // If notifications are enabled, schedule the first refresh #if os(iOS) if appEnvironment.settingsManager.backgroundNotificationsEnabled {