react-native-background-geolocation: Heartbeat event doesn't getting called in case of stationary location when app is killed.

Your Environment

  • Plugin version: react-native-background-geolocation": “3.9.3” & react-native-background-fetch": “3.0.6”
  • Platform: iOS and android
  • OS version: 13.5
  • Device manufacturer / model: iPhone SE (2nd gen)
  • React Native version (react-native -v): 0.62.2
  • Plugin config
export const configureBackgroundGeoLocation = () => {
  BackgroundGeolocation.ready(
    {
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: stores.locationStore.fetchRadius || 10, //distance required for getting location update        // Activity Recognition
      stopTimeout: 1,
      // 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.
      startOnBoot: true, // <-- Auto start tracking when device is powered-up.
      locationAuthorizationRequest: 'Always',
      heartbeatInterval: 60,
      preventSuspend: true, //required for heartbeat event for ios,
      foregroundService: true,
    },
    state => {
      LOGGER.log(
        '- BackgroundGeolocation is configured and ready: ',
        state.enabled,
      );

      if (!state.enabled) {
        BackgroundGeolocation.start(function() {
          LOGGER.log('- Start success');
        });
      }
    },
  );

BackgroundGeolocation.on('location', location => {
    console.log('On location:', location);
    location && getLocationInputAndSave(location);
  });

  /**
   * this will get called whenever it has been elapsed 1 min and device is sationary i.e there is no change in location from last 1min
   */
  BackgroundGeolocation.onHeartbeat(event => {
    // You could request a new location if you wish.

    BackgroundGeolocation.getCurrentPosition({
      samples: 1,
      persist: true,
    }).then(location => {
      console.log('On heartbeat:', location);
      // location && getLocationInputAndSave(location);
    });
  });

Expected Behavior

We should get stationary data by calling the heartbeat event even if the app is killed.

Actual Behavior

We are not getting stationary data when the app is killed although we are getting it when the app is in foreground or background state.

Steps to Reproduce

Context

Debug logs

Logs
PASTE_YOUR_LOGS_HERE

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25 (6 by maintainers)

Most upvoted comments

The plugin has nothing to do with GraphQL.

  • When your Android or iOS app is alive (either foreground or background), your hearbeat event arrives here:
BackgroundGeolocaiton.onHeartbeat((event) {
  console.log('[heartbeat]', event);
});
  • When your Android app is terminated, your heartbeat events (and all events) arrive in your registered headless-task.

An Android app has 3 states:

  • foreground
  • background
  • terminated.

“Headless” = terminated.

Okay, so there is no way to get stationary location updates on iOS based on heartbeat interval?

When the iOS app is terminated, no – It’s impossible.

Any other way?

No. It’s impossible.

@Reenagrg100 you should reach @christocracy for your issue as he is the best person to answer any of your question.