Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions docs/debugging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,61 @@ class AppDelegate: FlutterAppDelegate {
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)

WorkmanagerDebug.setCurrent(LoggingDebugHandler())

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
```

### 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
}
}
```

<Warning>
**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.
</Warning>

## Custom Debug Handlers

Create your own debug handler for custom logging needs:
Expand Down Expand Up @@ -361,4 +402,4 @@ Future<bool> 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.
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.
Loading