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.