Skip to content

🐞Periodic Task inputData Not Updating via Dart registerPeriodicTask on iOS #612

@ondramastik

Description

@ondramastik

Problem Description

When using flutter_workmanager on iOS, periodic tasks consistently receive inputData as null within the Workmanager().executeTask callback, despite being provided during registration. This issue is specific to iOS periodic tasks; Android periodic tasks and iOS one-off tasks function correctly.

Setup & Environment

  • Prerequisites Confirmed:

    • README read
    • Android setup done
    • iOS setup done
    • Sample app tested, issue reproducible there.
  • Workmanager Version: 0.7.0

  • Xcode Version: 16.1

  • Swift Version: 6.0.2

  • iOS Deployment Target: 18.1

Steps Taken & Observed Behavior

  1. iOS AppDelegate.swift Registration:
    A periodic task with identifier "my_task_name" is registered in AppDelegate.swift:
    WorkmanagerPlugin.registerPeriodicTask(withIdentifier: "my_task_name", frequency: NSNumber(value: 20 * 60))
  2. Info.plist Configuration:
    The task identifier "my_task_name" is added to Info.plist, and background processing and fetching capabilities are enabled.
  3. Flutter callbackDispatcher Task Registration:
    Inside the Workmanager().executeTask callback (which is triggered for the periodic task), the task is re-registered on the Flutter side with inputData:
    await Workmanager().registerPeriodicTask(
      "my_task_name",
      "my_task_name",
      frequency: const Duration(minutes: 20),
      initialDelay: const Duration(seconds: 30),
      existingWorkPolicy: ExistingWorkPolicy.replace,
      inputData: periodicAction.toInputData(), // periodicAction.toInputData() is confirmed to provide non-null data
      constraints: Constraints(networkType: NetworkType.connected),
    );
  4. Issue: When the periodic task executes on iOS, the inputData received in the Dart executeTask callback is always null.
  5. Suspected Cause: It's suspected that all executed periodic tasks originate from the initial iOS-side registration call, and subsequent registerPeriodicTask calls from the Flutter side (which provide inputData and other constraints) do not override or influence these tasks, even though logs indicate successful Flutter-side registration.

Relevant Logs & Diagnostics

  • Task Registration Logs (Example):

    BGAppRefreshTask submitted my_task_name earliestBeginInSeconds:30.0
    flutter: Registered periodic task "my_task_name" for widget 5 (storm_map)
    
  • flutter doctor -v Output:

    [✓] Flutter (Channel stable, 3.27.3, on macOS 15.5 24F74 darwin-arm64, locale en-US)
    [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    [✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2024.3)
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions