flutter_workmanager
                                
                                 flutter_workmanager copied to clipboard
                                
                                    flutter_workmanager copied to clipboard
                            
                            
                            
                        PeriodicTask on iOS
Hi there, I now that there are lots of other issues where this question is discussed. I just want to ask to ask what is the best way to create a periodic task on iOS?
What I know
- The current documentation says, that this is not supported.
- https://github.com/fluttercommunity/flutter_workmanager/issues/295 says, that is could be supported soon
- https://github.com/fluttercommunity/flutter_workmanager/issues/109 also raises hope
- In https://github.com/fluttercommunity/flutter_workmanager/issues/206 is said, that small batches are no problem. But I do not found an example. I just want to make an API-Request every 15 minutes like on Android. How can I achieve this?
So I'm very confused at the moment.
- Does the library support periodic background tasks on iOS now? How?
- If not: Is this feature in development or at least on the road map?
Thank you very much in advance!
Also in the same situation. Everything on Android works totally fine, but if I run the same code on iOS it always throws a PlatformException.
Same situation. iOS - PlatformException(unhandledMethod("registerPeriodicTask")
Same situation, has anyone been able to solve it ? I'm using this alternative to run in Android but not iOS.
Future<void> _fetchBackgrountLocation(
    Function callbackDispatcher, String fetchBackground) async {
  await Workmanager().initialize(
    callbackDispatcher,
    isInDebugMode: true,
  );
  if (Platform.isAndroid) {
    Workmanager().registerPeriodicTask(
      "1",
      fetchBackground,
      frequency: Duration(minutes: 15),
    );
  }
}
Same here, any update on this?
Most of the things says [Android Only] so i think this plugin is only for Android and not for the IOS
Part of the issue is the plugins current APIs.
registerPeriodicTask is indeed not working on iOS, because there is no equivalent.
The new BG task APIs support scheduling background work and once they are executed, you can schedule another piece of work with a minimumDelay, thus causing the illusion of periodic work. A lot of this is due to how iOS schedules background work.
PRs on documenting, testing etc are very welcome. The code is all visible in 0.5.0-dev.8.
Thanks for your answer!
Could you please provide a minimal example of an iOS background task that schedules another which schedules another one and so on?
And I personally think that it would be a good idea to use illusional periodic task for the registerPeriodicTask function on iOS. Even if this implementation might not be perfect it is still better than no implementation at all imho.
Part of the issue is the plugins current APIs.
registerPeriodicTaskis indeed not working on iOS, because there is no equivalent.The new BG task APIs support scheduling background work and once they are executed, you can schedule another piece of work with a minimumDelay, thus causing the
illusionof periodic work. A lot of this is due to how iOS schedules background work.
For others searching for an understanding of the various iOS tasking options, intentions and limitations there is an excellent video by Apple explaining as much here . This shows how tasking is in the hands of the OS and provides a guide on the most appropriate option for your purposes.
Man forget periodic, I cannot even do OneOff task on iOS. Hope they fix this soon.
Man forget periodic, I cannot even do OneOff task on iOS. Hope they fix this soon.
https://github.com/fluttercommunity/flutter_workmanager/issues/357#issuecomment-1028842173
@LostInDarkMath, I have to agree that the documentation is confusing. I am also not quite sure, which things are supported on both platforms.
Maybe someone who knows the intricacies of the plugin implementation could go over the documentation (and the comments in the code) and see that it accurately reflects what the plugin is doing.
it looks like flutter_local_notifications plugin has the ability to create periodic notifications in iOS: https://pub.dev/packages/flutter_local_notifications#periodically-show-a-notification-with-a-specified-interval. Also a short example of it here.
Why can't it be done the same here in the workmanager? (sorry, I'm not an iOS developer and may be missing smth)
Scheduled notifications and bgAppRefreshTask are very different.
You can schedule a notification. This notification will displayed at scheduled time.
A background work is called by iOS itself and has no possibility to schedule a specific time. The call is randomized by iOS- see apple documents for bgAppRefreshTask
@Stratovarius93 did you find a solution for iOS?
Hello there, any news?
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(unhandledMethod("registerPeriodicTask") error, Unhandled method registerPeriodicTask, null, null)
I'm facing this issue in IOS, android is working fine.
Any updates on this?
Check https://github.com/fluttercommunity/flutter_workmanager/pull/511 which has major enhancements for iOS