react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

crashes in production for android apps

Open NadeemKhanFh opened this issue 1 year ago • 2 comments

Your Environment

  • Plugin version: ^4.17.1
  • Platform: Android
  • OS version: android 9,
  • Device manufacturer / model:Tecno Spark 4
  • React Native version (react-native -v): "^0.74.5",
  • Plugin config
React.useEffect(() => {
    /// 1.  Subscribe to events.
    const onLocation: Subscription = BackgroundGeolocation.onLocation(
      (location) => {
        // console.log('[onLocation]', location);

        setLocationData({
          lat: location?.coords?.latitude,
          long: location?.coords?.longitude,
        });

        setIs_moving(location?.is_moving);
      }
    );

    const onMotionChange: Subscription = BackgroundGeolocation.onMotionChange(
      (event) => {
        // console.log('[onMotionChange]', event);
      }
    );

    const onActivityChange: Subscription =
      BackgroundGeolocation.onActivityChange((event) => {
        //  console.log('[onActivityChange]', event);
      });

    const onProviderChange: Subscription =
      BackgroundGeolocation.onProviderChange((event) => {
        // console.log('[onProviderChange]', event);
      });

    const onHttp = BackgroundGeolocation.onHttp((httpEvent) => {
      //console.log('[http] ', httpEvent);
    });

    const onAuthorization = BackgroundGeolocation.onAuthorization(
      (httpEvent) => {
        //  console.log('[onAuthorization] ', httpEvent);
      }
    );

    /// 2. ready the plugin.
    BackgroundGeolocation.ready({
      locationAuthorizationRequest: 'Always',
      disableLocationAuthorizationAlert: false,
      backgroundPermissionRationale: {
        title:
          "Allow Cheezious to access this device's location in the background?",
        message:
          'In order to track your activity in the background, please enable your backgoround location permission',
        positiveAction: 'Allow',
        negativeAction: 'Cancel',
      },
      notification: {
        title: 'Background Location Tracking',
        text: 'We are tracking your location to provide real-time updates.',
      },
      // Geolocation Config
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 100,
      // Activity Recognition
      stopTimeout: 5,
      // 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.
      // HTTP / SQLite config
      batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
      autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
      enableHeadless: true,
      url: `${Config.API_URL}riders/update/location`,
      method: 'POST',

      headers: {
        authorization: 'Bearer ' + token ?? '',
      },
    })
      .then((state) => {
        console.log(
          '- BackgroundGeolocation is configured and ready: ',
          state.enabled
        );
        if (!state.enabled) {
          BackgroundGeolocation.start();
        }
      })
      .catch((error) => {
        console.log('- BackgroundGeolocation error: ', error);

        if (error === 'Permission denied') {
          setShowLocationModal(true);
        }
      });

    return () => {
      // Remove BackgroundGeolocation event-subscribers when the View is removed or refreshed
      // during development live-reload.  Without this, event-listeners will accumulate with
      // each refresh during live-reload.
      onLocation.remove();
      onMotionChange.remove();
      onActivityChange.remove();
      onProviderChange.remove();
      onHttp.remove();
      onAuthorization.remove();
    };
  }, []);

Expected Behavior

It should not crash in production

Actual Behavior

It should not crash in production

Steps to Reproduce

its happening in production, i am sending screenshots 1. 2. 3. 4.

Context

Debug logs

Logs
PASTE_YOUR_LOGS_HERE
Screenshot 2024-10-09 at 3 04 38 PM Screenshot 2024-10-09 at 3 05 48 PM

NadeemKhanFh avatar Oct 09 '24 10:10 NadeemKhanFh

@christocracy ?? can you please comment on this?

NadeemKhanFh avatar Oct 12 '24 10:10 NadeemKhanFh

Have you tried searching the issues for that error?

christocracy avatar Oct 12 '24 13:10 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Nov 12 '24 02:11 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Nov 26 '24 02:11 github-actions[bot]