Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Periodic Task Not Triggering callbackDispatcher on Real Device but Works on Simulator #574

Open
rapkatt opened this issue Oct 23, 2024 · 11 comments

Comments

@rapkatt
Copy link

rapkatt commented Oct 23, 2024

App does not trigger the callbackDispatcher method on a real iOS device. However, the task works as expected on the iOS simulator.

Steps to Reproduce:
1. Schedule the task with a repeat interval (e.g., 15 min).
2.Deploy the app to a real iOS device and wait for the periodic task to trigger.
3.The task not trigger callbackDispatcher on the real device.

Test Methods:
- Waited more than an hour to see if the task triggers on the real device.
- Used Xcode's Debug -> Simulate background fetch to manually trigger the task.

Results:
- The task triggers and executes callbackDispatcher as expected on the iOS simulator.
- The task does not trigger at all on the real device, even after waiting or simulating a background fetch in Xcode.

Expected Behavior
- The periodic task should trigger the callbackDispatcher method both on the iOS simulator and real devices.

Flutter version: 3.24.3
WorkManager version:
git: url: https://github.com/fluttercommunity/flutter_workmanager.git
ref: b783000
iOS version: 17.5.1
Device: 11 Pro Max

Screenshot 2024-10-24 at 00 03 06

Screenshot 2024-10-24 at 00 03 44

Screenshot 2024-10-24 at 00 04 07

Screenshot 2024-10-24 at 00 04 33

@arun-gautham
Copy link

did this work, ?

@rapkatt
Copy link
Author

rapkatt commented Dec 2, 2024

@arun-gautham
Yes, it's work. I solved my problem with restarting the device

@claudiulazar
Copy link

I did exactly what @rapkatt showed in the first comment and the periodic task is not triggered at all ...

@rapkatt does it still work for you with the latest iOS?
@arun-gautham did you manage to make it work for your part?

@xunreal75
Copy link
Contributor

Please read apples documentation about background tasks. There is no BG-scheduler in iOS which safely starts your preferred update task . It's an normal apple behavior.
https://developer.apple.com/documentation/uikit/using-background-tasks-to-update-your-app

@arun-gautham
Copy link

Yes I got it to work perfectly fine

@jawad111
Copy link

Yes I got it to work perfectly fine

did you get callbackDispatcher to work with Workmanager().registerPeriodicTask ? how?

@arun-gautham
Copy link

arun-gautham commented Dec 31, 2024

Note the key "offcloud-file-upload" , update it as per your app

info plist:

         <key>UIBackgroundModes</key>
	<array>
	<string>processing</string>
	</array>
	<key>BGTaskSchedulerPermittedIdentifiers</key>
	<array>
		<string>offcloud-file-upload</string>
	</array>

Appdeletegate.swift
override func application(

  _ application: UIApplication,
   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
 ) -> Bool {
   GeneratedPluginRegistrant.register(with: self)
     WorkmanagerPlugin.setPluginRegistrantCallback {registry in
         GeneratedPluginRegistrant.register(with: registry)
     }
   **WorkmanagerPlugin.registerBGProcessingTask(withIdentifier: "offcloud-file-upload")
   return super.application(application, didFinishLaunchingWithOptions: launchOptions)**
 }

flutter

Workmanager().registerOneOffTask(
          "offcloud-file-upload",
          "offcloud-file-upload",
          constraints: Constraints(
            // connected or metered mark the task as requiring internet
            networkType: NetworkType.connected,
            // require suffucinat power
            requiresBatteryNotLow: true,
          ),

@ctenhank
Copy link

ctenhank commented Jan 2, 2025

@arun-gautham

Your example is OneOffTask, not PeriodicTask.

Are you sure that you did test using "PeriodicTask"?

@arun-gautham
Copy link

Actually no , I did a cron that kicks off a one off task. and as this did serve my purpose,
How ever I can give the periodic task a try as well in couple of days.

@jawad111
Copy link

jawad111 commented Jan 2, 2025

@rapkatt and @arun-gautham, are you both bots or something? 😄

@rapkatt: Honestly, I tried restarting five different devices with exact same setup, and it still didn't work, even on the emulators and after multiple restarts.

@arun-gautham: You keep mentioning it works without pointing out that you are referring to OneOffTask, but you're missing the crucial point that this entire discussion is based on Periodic Tasks. This is very misleading.

Yes I got it to work perfectly fine

Note the key "offcloud-file-upload" , update it as per your app

info plist:

         <key>UIBackgroundModes</key>
	<array>
	<string>processing</string>
	</array>
	<key>BGTaskSchedulerPermittedIdentifiers</key>
	<array>
		<string>offcloud-file-upload</string>
	</array>

Appdeletegate.swift override func application(

  _ application: UIApplication,
   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
 ) -> Bool {
   GeneratedPluginRegistrant.register(with: self)
     WorkmanagerPlugin.setPluginRegistrantCallback {registry in
         GeneratedPluginRegistrant.register(with: registry)
     }
   **WorkmanagerPlugin.registerBGProcessingTask(withIdentifier: "offcloud-file-upload")
   return super.application(application, didFinishLaunchingWithOptions: launchOptions)**
 }

flutter

Workmanager().registerOneOffTask(
          "offcloud-file-upload",
          "offcloud-file-upload",
          constraints: Constraints(
            // connected or metered mark the task as requiring internet
            networkType: NetworkType.connected,
            // require suffucinat power
            requiresBatteryNotLow: true,
          ),

@arun-gautham Yes, it's work. I solved my problem with restarting the device

@ctenhank
Copy link

ctenhank commented Jan 3, 2025

@jawad111

I think, he did test using "cron" and "workmanager" as mentioned.
(cron is for a repeat, and workmanager is for a background execution)

But, the "cron" may not work in background: agilord/cron#48 (comment).

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

No branches or pull requests

6 participants