react-native -v): 0.60.5Plugin config
```javascript
BackgroundGeolocation.onMotionChange(this.onMotionChange);
BackgroundGeolocation.onGeofence(this.onGeofence);
BackgroundGeolocation.onHeartbeat(this.onHeartbeat);
BackgroundGeolocation.ready(
{
reset: true,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
stationaryRadius: 25,
stopTimeout: 1,
preventSuspend: true,
foregroundService: true,
heartbeatInterval: 60,
enableHeadless: true,
debug: true,
autoSync: false
},
state => {
BackgroundGeolocation.resetOdometer(() => {
this.helpPrint("initial start resetting odometer");
});
BackgroundGeolocation.start(() => {
this.helpPrint("Start tracking success");
});
},
error => {
this.helpPrint(
"failed to start background tracking" + JSON.stringify(error)
);
}
);
## Expected Behavior
When the app is backgrounded onMotionChange, onGeofence, and onHeartbeat should still be firing. The actual methods here are appending text to the state of a component (BgGeo methods are within an owned class), and I'd expect the component to catch these state changes:
```javascript
onHeartbeat = event => {
this.helpPrint("[onHeartBeat] beat" + JSON.stringify(event));
};
AFAICT onMotionChange and onHeartbeat are sometimes triggered. With a heartbeat interval of heartbeatInterval: 60 I would expect timestamps to be consistently 1 minute apart, however I get missing timestamps whenever the app is backgrounded (Home button is pressed/swipe up from bottom of the screen), and inconsistent results when app is foregrounded but screen is asleep. Motion changes are more sporadic and seem to require the app be open and the device not slept to trigger event: Moving -> Not Moving (true -> false). Not Moving -> Moving seems to work once you make a significant distance change (200m) as the docs indicate.
Install and configure application as I have above
I'm trying to detect changes in movement particularly motion changes whenever the user enters/exits a geofence or stops/starts movement. The heartbeat triggers were just a testing tool. Am I configuring the plugin improperly, should I have the plugin be configured at index.js instead? The plugin lives at the home view of the application rather than App.js or index.js at the moment.
Logs
<!-- Syntax highlighting: DO NOT REMOVE -->
PASTE_YOUR_LOGS_HERE
In the SampleApp I use a number of events to draw markers on the map (location markers, geofence events). If I were experiencing a problem, shouldn鈥檛 there be chronic issues with missing markers on the map?
I always run the SampleApp on my device, built for release.
Right, I was hoping there was some obvious config that I'm misusing, or I'm just starting the plugin in the wrong place; I will experiment with the location event to see if I can get any different results there.
Do you have any tips on how to debug this issue?
Didn't mean to close the issue!
You do want to ensure you execute #ready each time your all boots, no matter what. Don鈥檛 bury the call to #ready within a view that must be explicitly navigated to after launch.
This should be easily tested in the simulator.
Thanks for your help, it seems after moving #ready into the App.js entrypoint the plugin is much more responsive to detecting movement changes; However, I do find that after a while of running in the background iOS seems to kill the app as the loading screen flashes before returning to the home screen.
I don't believe this is due to memory pressure as I'm only interested in motion and geofence changes, but do you have any recommendations on configurations or ways to prevent this from happening?
BackgroundGeolocation.onMotionChange(this.onMotionChange);
BackgroundGeolocation.onGeofence(this.onGeofence);
However, I do find that after a while of running in the background iOS seems to kill the app as the loading screen flashes
This is normal for any iOS app. You can expect that iOS will eventually terminate any suspended app sitting in the background for some period of time to free up memory for the app currently in the foreground. If the plugin has location-services ON and is currently tracking a device, iOS will never terminate that app (when the plugin is tracking, your app is no longer suspended).
If iOS has terminated your app while suspended in the background, the OS will automatically re-launch your app into the background when the device moves ~200 meters.
also - and this is more a question than a statement - I believe if you have react-native-background-fetch (a background-geolocation dependency) configured it will - after a period of settling in and assuming you don't do anything too heavy - wake the app up periodically / non-deterministically as well? To at least give you a hook to do something, maybe...
wake the app up periodically / non-deterministically as well? To at least give you a hook to do something
Correct.
Thanks for the help!
Most helpful comment
Correct.