I’m currently in the process of researching Ionic’s/Capacitor’s capabilities, for a cross platform ios/android app I’m planning to develop. One aspect the app needs to be capable of, is to be kept open in background, in order to take care of scheduled periodical tasks.
After doing some research today, I found out, that there seem to exist two ways to do that, but both seem to be flawed:
- There’s a native plugin, for keeping apps open in background, namely Background Mode - Ionic Documentation (ionicframework.com).
But its most commented GitHub issues seem to indicate that it does not work anymore: Issues · katzer/cordova-plugin-background-mode (github.com) . Also its last commit has been two years ago. So it basically seems to be dead in the water.
- And there is (or was?) an official plugin, too: Background Tasks - Capacitor (capacitorjs.com). But that is only available for Version 2.x of Capacitor. Its completely missing from the current docs: Capacitor Plugins - Capacitor (capacitorjs.com). So I assume that this won’t work either.
So can anyone tell me: what would be the best practice for implementing background scheduling, in a cross platform manner, with Ionic? Will there be a successor to the official background task plugin for version 3 of Capacitor? Am I overlooking something?
Any help would be much appreciated.
Thank you very much for replying. Sadly GitHub reveals (see here) that this always shows a notification and is therefore not the same as a real background task.
I’m slowly but surely beginning to wonder, if correct background-scheduling is even possible in Ionic/Capacitor…
For anyone who would like this feature to be implemented:
The ionic team has a GitHub issue for background tasks in Capacitor V3.
The issue is closed, but they gauge interest for this feature, by keeping an eye on how many users voted with a thumbs up reaction.
So if you’re interested in background tasks: go there and click on the “”-icon.
Another info for anyone interested:
There’s an up-to-date plugin for scheduling periodic background fetch operations (iOS explanation).
It seems to only be able to run every 15 minutes and puts you at the mercy of the OS, but comes in two flavors:
EDIT: Both are free and distributed under MIT License
(Displayed at the bottom of their respective GitHub pages)
Yes seems like a good option but it’s a paid plugin. Ive been searching a while about this topic and it seems there isn’t any real background tasks for hybrid apps, guess we keep on waiting
When I initially began researching about Ionic/Capacitor, I just assumed that periodic background scheduling would be a standard use case and exist for sure.
It turned out to be the biggest stumbling block I could encounter.
Periodic background scheduling in Capacitor/Ionic is virtually non-existent.
I’m gonna stick with the plugin I mentioned above for the time being (which is actually free and under MIT license).
But I truly wish this would become core functionality, rather sooner than later.
I’m sure there are lots of people who agree with you, but I am not one of them.
BITD, MacOS used to have what Apple (overly optimistically, IMHO) called “cooperative multitasking”. Each application was supposed to call
WaitNextEvent frequently, which was monkeypatched by the OS to yield CPU time to background tasks.
What actually happened in the real world was a tragedy of the commons, in which developers tended to hog the CPU in order to make their app be as fast as possible, with zero concern for the overall user experience. I see a similar dynamic involving background tasks in mobile OSes: they murder battery life.
I cannot tell you how many threads I have seen here on these forums from people who want to phone home every minute with device location and whatnot. I guess in closing all I can say is that if you ever do get the ability to do that, please make it easy to turn off and explain clearly to users how they can do so (disabling it by default would be even better, from my POV).
I have not been involved with phone app development until recently. So, coming from a PC mindset I was not aware of the problems associated with being able to freely choose execution intervals. But now that you explain it, it makes perfect sense…
Thank you for taking the time to weigh in on this topic. I’ll definitely keep your advice in mind.
Hi, can i make it for scheduled monthly
I want to monthly add data to sqlite database is it possible