LocationUpdates/Geofencing not running in background

Hi,

Let’s say we have three application states - foregrounded, backgrounded and terminated/suspended. The last one is also kind of a background state and is defined as an app that is completely closed (it doesn’t appear in multitasking managers). However, there are some cases where the app can be woken up from the terminated state and run some code, it could be JS code too - that’s the magic that TaskManager can do. Unfortunately waking up an app from that state is a bit limited on iOS and Android > 8.0, so simple location update cannot wake up your app, on iOS we use significant location updates feature to make it possible. When the significant location update arrives (it requires at least 500m movement!), TaskManager spins up a new JS context in a headless mode (without views), calls appropriate tasks, waits for them to be finished and destroys the context, so the app can fall asleep again, however it’s no longer in the terminated state. Afterwards, we switch back to standard location service (the app still won’t be present in the multitasking view).
Summarizing, after the significant location change that wakes up the app, you should be receiving normal location updates almost as often as in the foreground state. Also, remember that you need “Always” location permission on iOS to make it work as expected.

There is also one simple trick to trigger a significant location change. Kill your app manually when your task is started, then go to system settings, turn off location services, wait a moment and then turn it on. It may cause your app to wake up. To confirm whether the app has been woken up, I’d recommend to use Console app on macOS to see logs from your iOS device and filter them by EXTaskService :slightly_smiling_face:

I hope I helped :smile:

3 Likes