react-native-background-geolocation: Not getting data in killed moving state on iOS on any real-device.
Your Environment
Plugin version: react-native-background-geolocation": “3.9.3” & react-native-background-fetch": “3.0.6” Platform: iOS only OS version: 13.1.1,14.3 Device manufacturer / model: iPhone Xr and iPhone 12mini
React Native version (react-native -v): 0.62.2
export const configureBackgroundGeoLocation = () => {
BackgroundGeolocation.ready(
{
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: stores.locationStore.fetchRadius || 10, //distance required for getting location update // Activity Recognition
stopTimeout: 5, //this is a timer which runs when plugin eneter into it's stationary state
disableStopDetection: false, // this is not recommended because will NEVER disable location service until we call background geo location stop
// Application config
debug: false, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app and required for Headless JS ( android killing state)
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
locationAuthorizationRequest: 'Always',
preventSuspend: true, //required for heartbeat event for ios,keep your iOS app running indefinitely in the background and prevent the app to going to suspend mode
//android options
foregroundService: true,
// With Headless JS, you can continue to respond to BackgroundGeolocation events after your android app has been terminated (assuming you've configured stopOnTerminate: false). but there is no headless mode in iOS
enableHeadless: true,
},
state => {
LOGGER.log(
'- BackgroundGeolocation is configured and ready: ',
state.enabled,
);
if (!state.enabled) {
BackgroundGeolocation.start(function() {
LOGGER.log('- Start success');
});
}
},
);
/**
*1. calls a function whenever there is an update in location(update depends on distanceFilter=radius(coming from server))
*2. will be always get called for at least one time, even if there is no movement
*3. Will be fired for each recorded location
*/
BackgroundGeolocation.on('location', location => {
console.log('on location:', location);
location && getLocationInputAndSave(location);
});
// In Android, there is headless mode where we can receive different events like 'heartbeat', 'location' when our app is terminated. This is not available in android.
let BackgroundGeolocationHeadlessTask = async event => {
let location = event.params;
switch (event.name) {
case 'location':
console.log('on location in killed state:', location);
location && getLocationInputAndSave(location);
}
};
BackgroundGeolocation.registerHeadlessTask(BackgroundGeolocationHeadlessTask);
## Expected Behavior
I should receive location updates in the killed state on a real iOS device.
## Actual Behavior
I'm not getting location updates in the killed state on a real iOS device even after moving around 3-4kms. Although I'm getting it on in the simulator using "City-run".
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (8 by maintainers)
Correct. This is easily demonstrated in the iOS simulator.
No. See the Github repo for instructions on how to manually build the app onto your iOS device.
It’s not related to device or OS. It is either your code or the environment.