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

PeriodicTask on iOS #306

Open
LostInDarkMath opened this issue Aug 23, 2021 · 18 comments
Open

PeriodicTask on iOS #306

LostInDarkMath opened this issue Aug 23, 2021 · 18 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed iOS iOS specific

Comments

@LostInDarkMath
Copy link

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

So I'm very confused at the moment.

  1. Does the library support periodic background tasks on iOS now? How?
  2. If not: Is this feature in development or at least on the road map?

Thank you very much in advance!

@PascalGehring
Copy link

PascalGehring commented Aug 25, 2021

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.

@karthisu
Copy link

karthisu commented Sep 8, 2021

Same situation. iOS - PlatformException(unhandledMethod("registerPeriodicTask")

@Stratovarius93
Copy link

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),
    );
  }
}

@arbazKnarkz
Copy link

Same here, any update on this?

@arbazKnarkz
Copy link

Most of the things says [Android Only] so i think this plugin is only for Android and not for the IOS

@ened ened added documentation Improvements or additions to documentation enhancement New feature or request iOS iOS specific labels Jan 30, 2022
@ened
Copy link
Collaborator

ened commented Jan 30, 2022

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.

@ened ened added the help wanted Extra attention is needed label Jan 30, 2022
@LostInDarkMath
Copy link
Author

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.

@cormalenv
Copy link

cormalenv commented Jan 31, 2022

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.

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.

@saad197
Copy link

saad197 commented Feb 1, 2022

Man forget periodic, I cannot even do OneOff task on iOS. Hope they fix this soon.

@cormalenv
Copy link

Man forget periodic, I cannot even do OneOff task on iOS. Hope they fix this soon.

#357 (comment)

@lyio
Copy link

lyio commented Feb 9, 2022

@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.

@bdshadow
Copy link

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)

@xunreal75
Copy link
Contributor

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

@Myzel394
Copy link

@Stratovarius93 did you find a solution for iOS?

@ziqq
Copy link

ziqq commented Jul 7, 2023

Hello there, any news?

@junaidirshad098
Copy link

[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.

@mariomurrent-softwaresolutions

Any updates on this?

@absar
Copy link
Contributor

absar commented Apr 19, 2024

Check #511 which has major enhancements for iOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request help wanted Extra attention is needed iOS iOS specific
Projects
None yet
Development

No branches or pull requests