Keep app running in the background

I am testing out ionic badges (on the homescreen icon on my app). Basically, I have a service running that polls and checks for new data, like messages. When a new message is received, the user would be notified via the badge that something has occurred within the app that needs their attention. However when the app closes, the badges dont appear on the icon on the homescreen until I re-enter the app. How do I keep the app running in the background? Is this possible with ionic?

Not possible at this time, but there’s a proposal for a capacitor plugin.

Just found another capacitor plugin that maybe can be useful to you:

Hi @phild! I think using push notifications may support you better. Have you tried it? At the same time that you advise the user you can increase the badge on its phone home screen.

Hey @Hills90210 - i’m trying that one but so far no luck. Thanks for looking though!

Hey @TomCosta - I havent tried push notifications but I am trying the ionic badge, which I believe works very similarly to the push notifications (or maybe not?). I will look into it though.

Ultimately I think my issue is that once the app is in the background, the services halt until the app reopens again. So i’ve been trying to find a way to keep those services running while the app is in the background. I’ll still look into push notifications though.

Ahh okay, I get you now. There is nothing to do with notifications for sure. If your focus is to maintain the background services working, you may try the Capacitor Background Tasks to do it. Hope it helps.

Does not work for capacitor v3

Hello, yes, it is possible, you need to go to the settings and search for your application and turn on the gun in the background, click windows settings and applications and there you have properties and you have to mark it to work in the background, I did it and it’s ok

I dont see my app in the background refresh settings. I am not sure if it is because it is not deployed to the app store or something? It is currently running only on my phone through xCode.

This is not something missing in Ionic. This is something missing the native frameworks. Ionic cannot make plugins for something that Apple and Google don’t support. Basically they do not want you to be able to use all the battery of the device, so they don’t allow this.
For Android, some hacks exist, but for iOS they do not.
There are background workers that will work for a while, but the OS will eventually kill your background thread.

You need remote push notifications sent from a server for this purposes. It is possible to send notifications that are invisible to the user but are only meant to trigger some event in the app, like a background thread fetching data.

I participated on building the Covid detection app in my country, and here there is a specific API (Exposure notification API) which was necessary to keep the app running in the background.
We tried for a long time to build this for our selves, but it cannot be done. You cannot keep a background thread alive infinitely in a custom app. The purpose is to protect the users.

5 Likes