Skip to content

Commit 6b618a1

Browse files
authored
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.
1 parent 7f4f870 commit 6b618a1

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

docs/debugging.mdx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,61 @@ class AppDelegate: FlutterAppDelegate {
6969
_ application: UIApplication,
7070
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
7171
) -> Bool {
72+
GeneratedPluginRegistrant.register(with: self)
73+
7274
WorkmanagerDebug.setCurrent(LoggingDebugHandler())
75+
7376
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
7477
}
7578
}
7679
```
7780

7881
### Notification Debug Handler
7982

80-
Shows debug information as notifications:
83+
Shows debug information as notifications (helpful for seeing background task execution):
8184

8285
```swift
83-
WorkmanagerDebug.setCurrent(NotificationDebugHandler())
86+
// In your AppDelegate.swift
87+
import workmanager_apple
88+
89+
@main
90+
class AppDelegate: FlutterAppDelegate {
91+
override func application(
92+
_ application: UIApplication,
93+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
94+
) -> Bool {
95+
GeneratedPluginRegistrant.register(with: self)
96+
97+
// Set notification delegate first
98+
UNUserNotificationCenter.current().delegate = self
99+
100+
// Request notification permission
101+
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
102+
if granted {
103+
print("Notification permission granted")
104+
}
105+
}
106+
107+
// Enable notification debug handler
108+
WorkmanagerDebug.setCurrent(NotificationDebugHandler())
109+
110+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
111+
}
112+
113+
// REQUIRED: Override to show notifications when app is in foreground
114+
override func userNotificationCenter(
115+
_ center: UNUserNotificationCenter,
116+
willPresent notification: UNNotification,
117+
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
118+
completionHandler(.alert) // Show notification banner even if app is in foreground
119+
}
120+
}
84121
```
85122

123+
<Warning>
124+
**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.
125+
</Warning>
126+
86127
## Custom Debug Handlers
87128

88129
Create your own debug handler for custom logging needs:
@@ -361,4 +402,4 @@ Future<bool> isTaskHealthy(String taskName, Duration maxAge) async {
361402
- [ ] Error handling with try-catch blocks
362403
- [ ] iOS 30-second execution limit respected
363404

364-
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.
405+
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.

0 commit comments

Comments
 (0)