react-native-background-geolocation: OnLocation is getting called thousands of times and crashes the app

Your Environment

  • Plugin version: 4.11.1
  • Platform: iOS
  • OS version: A lot. I’ve seen everything between iOS 15.6.1 to 16.6
  • Device manufacturer / model: Mainly iPads
  • React Native version (react-native -v): 0.71.8
  • Plugin config
  BackgroundGeolocation.ready({
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        distanceFilter: 50,
        stopTimeout: 60 * 10,
        debug: false,
        stopOnTerminate: true
      });

Expected Behavior

I expect the callback BackgroundGeolocation.onLocation to be called every 50 meters.

Actual Behavior

Based on our internal logs it sometimes gets executed thousands of times in a matter of seconds. From what’ve seen, it seems to be mainly happening on iPads.

Steps to Reproduce

Haven’t been able to reproduce it:

My code:

  useEffect(() => {
    let onLocation;
    if (trackActivity) {
      onLocation = BackgroundGeolocation.onLocation(location => {
        ...
      });

      BackgroundGeolocation.ready({
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        distanceFilter: 50,
        stopTimeout: 60 * 10,
        debug: false,
        stopOnTerminate: true
      });
    }
    return () => {
      if (onLocation) onLocation.remove();
    };
  }, []);

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

You don’t need to worry about listeners on a “killed” app since your app will have been removed from memory.