From 6b618a15cf93c4879677c04eb97b8cda22fc7f7c Mon Sep 17 00:00:00 2001 From: kq1231 <88677687+kq1231@users.noreply.github.com> Date: Tue, 3 Feb 2026 23:56:03 +0500 Subject: [PATCH] Add missing userNotificationCenter override for iOS notification debugging ## Problem The iOS Notification Debug Handler section is incomplete - it's missing the `userNotificationCenter` override that's required to show notifications when the app is in foreground. Without this, debug notifications don't appear during development. ## Solution Added complete iOS setup showing: - Notification permission request - Delegate assignment - Critical `userNotificationCenter` override ## Testing Tested on iOS 26. Debug notifications now appear correctly. --- docs/debugging.mdx | 47 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/docs/debugging.mdx b/docs/debugging.mdx index 3626d292..23fd7ecb 100644 --- a/docs/debugging.mdx +++ b/docs/debugging.mdx @@ -69,7 +69,10 @@ class AppDelegate: FlutterAppDelegate { _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + WorkmanagerDebug.setCurrent(LoggingDebugHandler()) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } @@ -77,12 +80,50 @@ class AppDelegate: FlutterAppDelegate { ### Notification Debug Handler -Shows debug information as notifications: +Shows debug information as notifications (helpful for seeing background task execution): ```swift -WorkmanagerDebug.setCurrent(NotificationDebugHandler()) +// In your AppDelegate.swift +import workmanager_apple + +@main +class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + + // Set notification delegate first + UNUserNotificationCenter.current().delegate = self + + // Request notification permission + UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in + if granted { + print("Notification permission granted") + } + } + + // Enable notification debug handler + WorkmanagerDebug.setCurrent(NotificationDebugHandler()) + + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } + + // REQUIRED: Override to show notifications when app is in foreground + override func userNotificationCenter( + _ center: UNUserNotificationCenter, + willPresent notification: UNNotification, + withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + completionHandler(.alert) // Show notification banner even if app is in foreground + } +} ``` + +**Important:** The `userNotificationCenter` override is required to display debug notifications when your app is in the foreground. Without it, you'll only see notifications when the app is in the background. + + ## Custom Debug Handlers Create your own debug handler for custom logging needs: @@ -361,4 +402,4 @@ Future isTaskHealthy(String taskName, Duration maxAge) async { - [ ] Error handling with try-catch blocks - [ ] iOS 30-second execution limit respected -Remember: Background task execution is controlled by the operating system and is never guaranteed. Always design your app to work gracefully when background tasks don't run as expected. \ No newline at end of file +Remember: Background task execution is controlled by the operating system and is never guaranteed. Always design your app to work gracefully when background tasks don't run as expected.