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

BackgroundGeolocation.onHttp() and the related POST to server stops running

Open russmenum opened this issue 3 years ago • 8 comments

Your Environment

  • Plugin version: "^4.1.1"
  • Platform: iOS
  • OS version: 15.2
  • Device manufacturer / model: Simulatore and iPhone SE
  • React Native version (react-native -v): "~0.63.4"
  • Plugin config
const configureBackgroundGeolocation = async () => {
      // ////
      // // 1.  Wire up event-listeners
      // //

      // // This handler fires whenever bgGeo receives a location update.
      // BackgroundGeolocation.onLocation(onLocation, onError);

      // // This handler fires when movement states changes (stationary->moving; moving->stationary)
      // BackgroundGeolocation.onMotionChange(onMotionChange);

      // // This event fires when a change in motion activity is detected
      // BackgroundGeolocation.onActivityChange(onActivityChange);

      // // This event fires when the user toggles location-services authorization
      // BackgroundGeolocation.onProviderChange(onProviderChange);

      // ////
      // // 2.  Execute #ready method (required)
      // //
      BackgroundGeolocation.ready({
        // Geolocation Config
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        distanceFilter: meterFromBackEndContext,//25,//updated from 150 last ver
        // 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.
        // HTTP / SQLite config
        url: `${url}`,
        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.
        headers: {              // <-- Optional HTTP headers
          "Accept": "application/json",
          "Content-Type": "application/json",
          "Authorization": `Bearer ${userToken}`,
        },
        // params: {               // <-- Optional HTTP params
        //   "auth_token": "maybe_your_server_authenticates_via_token_YES?"
        // },
        //httpRootProperty: 'body',
        locationTemplate: '{"lat":<%= latitude %>,"lng":<%= longitude %>}',
        extras: {
          "driver": `${userNameContext.toLowerCase().trim()} (iOS), ${deliveryMM_order_id}`,
          "title": "ping",
          "appver": `${appVersion}`,
          "users_id": `${userIDContext}`,
          "establishment_user_id": `${establishmentIDContext}`
        }
      }, (state) => {
        console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);

        if (!state.enabled) {
          ////
          // 3. Start tracking!
          //
          BackgroundGeolocation.start(function() {
            console.log("- Start success");
          });
        }
      });
    };

Additional:

    BackgroundGeolocation.onLocation(location => {
      console.log("[location] ", location);
    }, error => {
      console.log("[location] ERROR: ", error);
    });
    BackgroundGeolocation.onHttp((response) => {
      console.log("[onHttp] ", response);
    });

Expected Behavior

I would expect [onHttp] to keep running and the change in location to keep getting posted to the server.

Actual Behavior

After a while, I keep seeing the console.log("[location] ", location); when debugging in the simulator, but the console.log("[onHttp] ", response); stops, and as far as I can tell nothing is being sent to the server BE anymore.

Steps to Reproduce

  1. Start tracking
  2. let it run logging
  3. put app in the background as intended ( I just opened settings in the simulator for this test)
  4. Wait ( I started this test at 3PM it ran fine, Mac was asleep overnight, on resume this morning some console.log("[onHttp] ", response); when I turned everything on then nothing. Just the locations...

Context

Trying to track a phone in the background. While drivers and other people are using it for other things.

It works great for a while, then for whatever reason, the phone seems to know the location to send, but the background task locks up and stops posting it to the server which defeats the whole point.

Toggling tracking on and off fixes this, but again the point is to track during a whole shift or run of things.

Debug logs

Logs
[Thu Feb 17 2022 14:49:17.428]  LOG      [location]  {"activity": {"confidence": 100, "type": "unknown"}, "battery": {"is_charging": false, "level": -1}, "coords": {"accuracy": 5, "altitude": 0, "altitude_accuracy": -1, "floor": 0, "heading": 5.98, "heading_accuracy": 0, "latitude": 37.72080811, "longitude": -122.44811106, "speed": 33.59, "speed_accuracy": 0}, "event": "motionchange", "extras": {"appver": "1.0.5", "driver": "test42 (iOS), null", "establishment_user_id": "34", "title": "ping", "users_id": "3"}, "is_moving": true, "odometer": 269.2, "timestamp": "2022-02-17T19:49:17.412Z", "uuid": "DF687C03-E3D7-4092-BC91-C158F3D3799A"}
[Thu Feb 17 2022 14:49:17.429]  LOG      [location]  {"activity": {"confidence": 100, "type": "unknown"}, "battery": {"is_charging": false, "level": -1}, "coords": {"accuracy": 5, "altitude": 0, "altitude_accuracy": -1, "floor": 0, "heading": 5.98, "heading_accuracy": 0, "latitude": 37.72080811, "longitude": -122.44811106, "speed": 33.59, "speed_accuracy": 0}, "event": "motionchange", "extras": {"appver": "1.0.5", "driver": "test42 (iOS), null", "establishment_user_id": "34", "title": "ping", "users_id": "3"}, "is_moving": true, "odometer": 269.2, "timestamp": "2022-02-17T19:49:17.412Z", "uuid": "DF687C03-E3D7-4092-BC91-C158F3D3799A"}
[Thu Feb 17 2022 14:49:17.663]  LOG      [onHttp]  {"responseText": "{\"success\":true,\"data\":{\"driver\":\"test42 (iOS), null\",\"appver\":\"1.0.5\",\"establishment_user_id\":34,\"title\":\"ping\",\"users_id\":3,\"lng\":-122.44811106,\"lat\":37.72080811,\"id\":193739}}", "status": 200, "success": true}


[Fri Feb 18 2022 09:02:28.165]  LOG      [onHttp]  {"responseText": "{\"success\":true,\"data\":{\"driver\":\"test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)\",\"appver\":\"1.0.5\",\"establishment_user_id\":34,\"title\":\"ping\",\"users_id\":3,\"lng\":-122.11764607,\"lat\":37.35772158,\"id\":198982}}", "status": 200, "success": true}
[Fri Feb 18 2022 09:02:28.165]  LOG      [onHttp]  {"responseText": "{\"success\":true,\"data\":{\"driver\":\"test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)\",\"appver\":\"1.0.5\",\"establishment_user_id\":34,\"title\":\"ping\",\"users_id\":3,\"lng\":-122.11764607,\"lat\":37.35772158,\"id\":198982}}", "status": 200, "success": true}
[Fri Feb 18 2022 09:02:28.165]  LOG      [onHttp]  {"responseText": "{\"success\":true,\"data\":{\"driver\":\"test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)\",\"appver\":\"1.0.5\",\"establishment_user_id\":34,\"title\":\"ping\",\"users_id\":3,\"lng\":-122.11764607,\"lat\":37.35772158,\"id\":198982}}", "status": 200, "success": true}
[Fri Feb 18 2022 09:02:28.165]  LOG      [onHttp]  {"responseText": "{\"success\":true,\"data\":{\"driver\":\"test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)\",\"appver\":\"1.0.5\",\"establishment_user_id\":34,\"title\":\"ping\",\"users_id\":3,\"lng\":-122.11764607,\"lat\":37.35772158,\"id\":198982}}", "status": 200, "success": true}
[Fri Feb 18 2022 09:02:28.166]  LOG      [onHttp]  {"responseText": "{\"success\":true,\"data\":{\"driver\":\"test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)\",\"appver\":\"1.0.5\",\"establishment_user_id\":34,\"title\":\"ping\",\"users_id\":3,\"lng\":-122.11764607,\"lat\":37.35772158,\"id\":198982}}", "status": 200, "success": true}
[Fri Feb 18 2022 09:02:28.166]  LOG      [onHttp]  {"responseText": "{\"success\":true,\"data\":{\"driver\":\"test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)\",\"appver\":\"1.0.5\",\"establishment_user_id\":34,\"title\":\"ping\",\"users_id\":3,\"lng\":-122.11764607,\"lat\":37.35772158,\"id\":198982}}", "status": 200, "success": true}
[Fri Feb 18 2022 09:02:28.166]  LOG      [location]  {"activity": {"confidence": 100, "type": "unknown"}, "battery": {"is_charging": false, "level": -1}, "coords": {"accuracy": 5, "altitude": 0, "altitude_accuracy": -1, "floor": 0, "heading": 328.01, "heading_accuracy": 0, "latitude": 37.35846644, "longitude": -122.11829223, "speed": 33.7, "speed_accuracy": 0}, "extras": {"appver": "1.0.5", "driver": "test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)", "establishment_user_id": "34", "title": "ping", "users_id": "3"}, "is_moving": true, "odometer": 664830.4, "timestamp": "2022-02-18T14:00:09.064Z", "uuid": "7D69503F-12A3-4AE9-9BB7-C8266AD67183"}
[Fri Feb 18 2022 09:02:28.166]  LOG      [location]  {"activity": {"confidence": 100, "type": "unknown"}, "battery": {"is_charging": false, "level": -1}, "coords": {"accuracy": 5, "altitude": 0, "altitude_accuracy": -1, "floor": 0, "heading": 328.01, "heading_accuracy": 0, "latitude": 37.35846644, "longitude": -122.11829223, "speed": 33.7, "speed_accuracy": 0}, "extras": {"appver": "1.0.5", "driver": "test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)", "establishment_user_id": "34", "title": "ping", "users_id": "3"}, "is_moving": true, "odometer": 664830.4, "timestamp": "2022-02-18T14:00:09.064Z", "uuid": "7D69503F-12A3-4AE9-9BB7-C8266AD67183"}
[Fri Feb 18 2022 09:02:28.166]  LOG      [location]  {"activity": {"confidence": 100, "type": "unknown"}, "battery": {"is_charging": false, "level": -1}, "coords": {"accuracy": 5, "altitude": 0, "altitude_accuracy": -1, "floor": 0, "heading": 328.01, "heading_accuracy": 0, "latitude": 37.35846644, "longitude": -122.11829223, "speed": 33.7, "speed_accuracy": 0}, "extras": {"appver": "1.0.5", "driver": "test42 (iOS), Thu Feb 17 2022 15:02:30 GMT-0500 (EST)", "establishment_user_id": "34", "title": "ping", "users_id": "3"}, "is_moving": true, "odometer": 664830.4, "timestamp": "2022-02-18T14:00:09.064Z", "uuid": "7D69503F-12A3-4AE9-9BB7-C8266AD67183"}

Overall am glad to have bought this, but really need a way to keep the phone sleep what not from ending the background reporting position until the user resets it

russmenum avatar Feb 18 '22 15:02 russmenum

There have been a number of reports of problems with iOS 15.2 Geofencing & Significant Location Changes APIs from all over the place.

The plugin relies on both of these apis in order to determine when the device is moving so it can engage location-tracking.

The problem is apparently fixed in iOS 15.4 (beta). I have a number of users of my Cordova, Capacitor, Flutter and React Native version who have confirmed that installing iOS 15.4 fixes their issues.

christocracy avatar Feb 18 '22 16:02 christocracy

I don't know if that's what you're experiencing.

If there is a location recorded and the plugin has an HTTP connection, an http request will be attempted. The plugin will keep attempting to upload all recorded locations until a network connection does become available.

The plugin does not "just stop uploading locations" for no reason, even while it continues to record locations.

christocracy avatar Feb 18 '22 16:02 christocracy

I suggest you fetch logs from the plugin (using the .emailLog method; see the wiki Debugging).

christocracy avatar Feb 18 '22 16:02 christocracy

If I do this

BackgroundGeolocation.logger.emailLog('[email protected]').then((success) => {
  console.log('[emailLog] SUCCESS');
}).catch((error) => {
  console.log('[emailLog] ERROR: ', error);
});

Is it using their email? LIke their outbox would show them the email? I ask because of the TOS and privacy whatnot, we may or may not have that email, and are not looking to data-mine people.

As far as:

I don't know if that's what you're experiencing.

If there is a location recorded and the plugin has an HTTP connection, an http request will be attempted. The plugin will keep attempting to upload all recorded locations until a network connection does become available.

The plugin does not "just stop uploading locations" for no reason, even while it continues to record locations.

This seems to be half what happened this morning. Basically, a bunch of points are bulk posted. Then it stopped.

Then when you turn to track back on, it looks like it then tried to post all the ones it did not, or was not. The BE went a little nuts for a few min why that happen.

Basically need it so the user should not need to toggle tracking off then on for the points to resume posting to the BE.

I will also take a look at 15.4... But my understanding is the Geofencing & Significant Location Changes would affect if a location was triggered not if it would trigger the HTTP post?

russmenum avatar Feb 18 '22 17:02 russmenum

Is it using their email?

Yes. You are supposed to reproduce this on your own device.

christocracy avatar Feb 18 '22 17:02 christocracy

There have been a number of reports of problems with iOS 15.2 Geofencing & Significant Location Changes APIs from all over the place.

The plugin relies on both of these apis in order to determine when the device is moving so it can engage location-tracking.

The problem is apparently fixed in iOS 15.4 (beta). I have a number of users of my Cordova, Capacitor, Flutter and React Native version who have confirmed that installing iOS 15.4 fixes their issues.

Can I know which beta version? I tried using 15.4 Beta 3, seems like still got same problem.

xnuxer88 avatar Feb 20 '22 12:02 xnuxer88

Create for me a simple RN Hello World app which reproduces the issue and share that in a public repo for me.

christocracy avatar Feb 20 '22 12:02 christocracy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar Apr 27 '22 16:04 stale[bot]

Buenas noches,

Presento el mismo inconveniente.

React Native versión: 0.70.8 react native background geolocation: 4.13.1

uppersap avatar Nov 15 '23 04:11 uppersap