I only get location updates/geofence updates when the app is running. I’ve put "UIBackgroundModes": ["location", "fetch"]in my app.json (and it shows up in my Info.plist), I’ve defined the task in the global scope, have given my app “always” as well as “background refresh” permissions, but I can’t seem to get it to run in the background.
I know it doesn’t work because there are no requests being made to the server until I opened the app, nor any LocalNotifications generated when I entered and exited two geofences this morning.
I drove 6.5 miles to the gym and back (well over apple’s “significant” location change threshold, on top of the gym being a geofenced region passed to the task), and there was no significant location update nor a geofence update. What am I doing wrong?
I suppose it’s both as I’ve instantiated the same background functions in both the client and my standalone
Forgot I turned off “Always” tracking in the client. It works in the expo client but not the standalone.
Correction, sorry - I forgot I turned off “Always” tracking in the expo client & after turning back on, I am receiving it from the client, but not the standalone. I determine this by prefixing the log with ‘dev/’ if it’s in dev, so it is working in the client but not the standalone.
Hey guys, sorry I didn’t have time to take a look on that, but I’ll try to find some time soon
So, to sum up, background location works for you on both Expo Client and standalone app, but geofencing works only in Expo Client, right?
Thanks @tsapeta for taking a look.
Background location (Location.startLocationUpdatesAsync) works for me on both Expo Client and standalone app.
Geofencing (Location.startGeofencingAsync) doesn’t work at all on either.
I just ran another test with both tasks registered and Location Update is working fine, I entered and exited the location specified in my geofencing and didn’t receive a single geofencing event; though location update worked perfectly and reported correct lat/longs all along the way.
It seems like I can build my own geofencing algo using location updates, but it would be nice to use something standard.
Location does stop reporting (as configured) and switches to background location reporting, which is either after a “significant” location change (500m according to apple’s docs) or if the device enters/exits a geofence
Hi,
Thank you for giving us the example, I got this error “GEO LOCATION UPDATE undefined” when testing your example.
Could you help me with this?
Thanks
Hmmm, is your TaskManager.defineTask(‘GEO_LOCATION_UPDATE’) running before Location.startLocationUpdateAsync.
From Expo documentation TaskManager.defineTask(taskName, task) Defines task function. It must be called in the global scope of your JavaScript bundle. In particular, it cannot be called in any of React lifecycle methods like componentDidMount. This limitation is due to the fact that when the application is launched in the background, we need to spin up your JavaScript app, run your task and then shut down — no views are mounted in this scenario.
Ideally all your TaskManager.defineTasks run outside of components, somewhere in the initial app setup code.
Then you fire off startLocationUpdateAsync in one of your components based on user input or something else.