Flutter library that basically makes a call every "x" minutes if the app is in the background.

Hi everyone, could you help us?

We implemented a Flutter library that basically makes a call every x minutes if the app is in the background, but when I generate the version via TestFlight for testing, it doesn't work.

Can you help us understand why? Below is a more detailed technical description.

Apple Developer Technical Support Request

Subject: BGTaskScheduler / Background Tasks Not Executing in TestFlight - Flutter App with workmanager Plugin

Issue Summary

Background tasks scheduled using BGTaskScheduler are not executing when the app is distributed via TestFlight. The same implementation works correctly when running the app locally via USB/Xcode debugging.

We are developing a Flutter application that needs to perform periodic API calls when the app is in the background. We have followed all documentation and implemented the required configurations, but background tasks are not being executed in the TestFlight build.

App Information

FieldValue
App Version3.1.15 (Build 311)
iOS Minimum Deployment TargetiOS 15.0
FrameworkFlutter
Flutter SDK Version^3.7.2

Technical Environment

Flutter Dependencies (Background Task Related)

PackageVersionPurpose
workmanager^0.9.0+3Main background task scheduler (uses BGTaskScheduler on iOS 13+)
flutter_background_service^5.0.5Background service management
flutter_background_service_android^6.2.4Android-specific background service
flutter_local_notifications^19.4.2Local notifications for background alerts
timezone^0.10.0Timezone support for scheduling

Other Relevant Flutter Dependencies

PackageVersion
firebase_core4.0.0
firebase_messaging(via native Podfile)
sfmc (Salesforce Marketing Cloud)^9.0.0
geolocator^14.0.0
permission_handler^12.0.0+1

Info.plist Configuration

We have added the following configurations to Info.plist:

UIBackgroundModes


<key>UIBackgroundModes</key>

<array>
    <string>location</string>
    <string>remote-notification</string>
    <string>processing</string>
</array>

### BGTaskSchedulerPermittedIdentifiers

```xml
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
    <string>br.com.unidas.apprac.ios.workmanager.carrinho_api_task</string>

<string>br.com.unidas.apprac.ios.workmanager</string>
<string>be.tramckrijter.workmanager.BackgroundTask</string>
</array>

**Note:** We included multiple identifier formats as recommended by the `workmanager` Flutter plugin documentation:

1. `{bundleId}.ios.workmanager.{taskName}` - Custom task identifier
2. `{bundleId}.ios.workmanager` - Default workmanager identifier
3. `be.tramckrijter.workmanager.BackgroundTask` - Plugin's default identifier (as per plugin documentation)

## AppDelegate.swift Configuration
We have configured the `AppDelegate.swift` with the following background processing setup:

```swift

// In application(_:didFinishLaunchingWithOptions:)

// Configuration to enable background processing via WorkManager
// The "processing" mode in UIBackgroundModes allows WorkManager to use BGTaskScheduler (iOS 13+)
// This is required to execute scheduled tasks in background (e.g., API calls)
// Note: User still needs to have Background App Refresh enabled in iOS settings

if UIApplication.shared.backgroundRefreshStatus == .available {
    // Allows iOS system to schedule background tasks with minimum interval
    UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
}

## WorkManager Implementation (Dart/Flutter)

### Initialization

```dart

/// Initializes WorkManager

static Future<void> initialize() async {
  await Workmanager().initialize(callbackDispatcher, isInDebugMode: false);
  print('WorkManagerService: WorkManager initialized');
}

### Task Registration
/// Schedules API execution after a specific delay

## Observed Behavior

### Works (Debug/USB Connection)
- When running the app via Xcode/USB debugging
- Background tasks are scheduled and executed as expected
- API calls are made successfully when the app is backgrounded

### Does NOT Work (TestFlight)
- When the app is distributed via TestFlight
- Background tasks appear to be scheduled (no errors in code)
- Tasks are **never executed** when the app is in background
- We have tested with:
  - Background App Refresh enabled in iOS Settings
  - App used frequently
  - Device connected to WiFi and charging
  - Waited for extended periods (hours)

## Possible heart points

1. **Are there any additional configurations required for `BGTaskScheduler` to work in TestFlight/Production builds that are not required for debug builds?**
2. **Is the identifier format correct?** We are using:
`br.com.unidas.apprac.ios.workmanager.carrinho_api_task`
   - Should it match exactly with the task name registered in code?
3. **Are there any known issues with Flutter's `workmanager` plugin and iOS BGTaskScheduler in production environments?**
4. **Is there any way to verify through logs or system diagnostics if the background tasks are being rejected by the system?**
5. **Could there be any conflict between our other background modes (`location`, `remote-notification`) and `processing`?**
6. **Does the Salesforce Marketing Cloud SDK (SFMC) interfere with BGTaskScheduler operations?**

## Additional Context

- We have verified that `Background App Refresh` is enabled for our app in iOS Settings
- The app has proper entitlements for push notifications and location services
- Firebase, SFMC (Salesforce Marketing Cloud), and other SDKs are properly configured
- The issue is **only** present in TestFlight builds, not in debug/USB-connected builds

## References

- [Apple Documentation - BGTaskScheduler](https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler)
- [Apple Documentation - Choosing Background Strategies](https://developer.apple.com/documentation/backgroundtasks/choosing_background_strategies_for_your_app)

Thank you
Flutter library that basically makes a call every "x" minutes if the app is in the background.
 
 
Q