Skip to content

feat: expose BGHealthResearchTask through public Dart API#664

Closed
jduhamel wants to merge 5 commits intofluttercommunity:mainfrom
UHN:feature/background-health-task
Closed

feat: expose BGHealthResearchTask through public Dart API#664
jduhamel wants to merge 5 commits intofluttercommunity:mainfrom
UHN:feature/background-health-task

Conversation

@jduhamel
Copy link
Copy Markdown

Summary

  • Thread registerHealthResearchTask() through the federated plugin architecture (platform interface → Apple impl → Android UnsupportedError → public Workmanager facade)
  • Fix missing registerHealthResearchTask override in Android Kotlin WorkmanagerPlugin (required by Pigeon-generated WorkmanagerHostApi interface added in 85b94bc)

Builds on 85b94bc which added the native iOS implementation and Pigeon bindings but did not expose the feature through the Dart API.

Breaking Changes

None — additive API only.

Files Changed

Layer File Change
Platform Interface workmanager_platform_interface/.../workmanager_platform_interface.dart Abstract method + placeholder
Apple workmanager_apple/lib/workmanager_apple.dart Pigeon API call
Android (Dart) workmanager_android/lib/workmanager_android.dart UnsupportedError
Android (Kotlin) WorkmanagerPlugin.kt UnsupportedOperationException stub
Public API workmanager/lib/src/workmanager_impl.dart Public facade method
Tests workmanager_apple/test/, workmanager/test/ Request validation + mock tests

jduhamel and others added 5 commits October 14, 2025 07:36
Add support for BGHealthResearchTask, a background task type specifically designed for HealthKit research operations.

Changes:
- Added backgroundHealthResearchTask case to BackgroundMode enum
- Implemented handleHealthResearchTask handler for task execution
- Added registerHealthResearchTask @objc method for AppDelegate registration
- Added scheduleHealthResearchTask for task scheduling
- Added HealthResearchTaskRequest to Pigeon API
- Updated generated Pigeon files for iOS, Android, and Dart

Requirements:
- iOS 15.0 or later
- com.apple.developer.healthkit.background-delivery entitlement
…utter compatibility

- Move Package.swift to ios/workmanager_apple/ subdirectory (Flutter SPM requirement)
- Rename product from 'workmanager_apple' to 'workmanager-apple' (Flutter naming convention)
- Add missing UIKit import in Extensions.swift for UIBackgroundFetchResult
- Move Sources, Resources, Assets to correct subdirectory

This fixes Swift Package Manager integration with Flutter's SPM plugin system,
which expects:
1. Package.swift at ios/<plugin_name>/Package.swift
2. Product names with hyphens (e.g., 'workmanager-apple' not 'workmanager_apple')

Without these fixes, Flutter falls back to CocoaPods instead of using SPM.
## Problem
The current Quick Start guide shows task identifiers that don't match between Dart and iOS native code, which causes `BGTaskSchedulerErrorDomain Code 3` errors on iOS.

**Current Issue:**
- Info.plist: `com.yourapp.processing_task`
- AppDelegate: `com.yourapp.processing_task`
- Dart code: `"data_sync"` ❌ (doesn't match!)

This mismatch prevents iOS background tasks from being scheduled successfully.

## Solution
Update documentation to show that **all three locations must use the same identifier**:
- Info.plist: `com.yourapp.processing_task`
- AppDelegate: `com.yourapp.processing_task`
- Dart code: `com.yourapp.processing_task` ✅

## Testing
Tested on iOS 26 with BGTaskScheduler - background tasks now schedule successfully without Code 3 errors.
…gging

## 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.
Thread registerHealthResearchTask() through the federated plugin
architecture: platform interface, Apple implementation, Android
UnsupportedError, and public Workmanager facade.

Also fix missing registerHealthResearchTask override in Android
Kotlin WorkmanagerPlugin (required by Pigeon-generated interface).
@docs-page
Copy link
Copy Markdown

docs-page bot commented Mar 24, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/fluttercommunity/flutter_workmanager~664

Documentation is deployed and generated using docs.page.

@jduhamel jduhamel closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants