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

setConfig does not update extras object

Open mahesh-agrawal-616 opened this issue 2 years ago • 7 comments

Your Environment

  • Plugin version:3.9.3
  • Platform: iOS or Android: iOS
  • OS version: 15.2
  • Device manufacturer / model: iPhone 13 Pro
  • React Native version (react-native -v): 0.63.4
  • Plugin config extras
BackgroundGeolocation.setConfig({
    schedule: [schedule],
    stopAfterElapsedMinutes: totalMinutes,
    distanceFilter: trackingConfig.DistanceFilter || 50,
    stopTimeout: trackingConfig.TrackingInterval || 3,
    method: "POST",
    url: nodeURL + 'geoTracking/TrackLocation',
    batchSync: false,
    autoSync: true,
    extras: {
        "EmployeeId": userInfo.EmployeeID,
        "EmployerId": userInfo.Employerid,
        "DeviceUDID": deviceId,
        "DeviceType": deviceType,
        "TripUDID": tripUDID,
    },
}).then((state) => {
    console.log("Tracking is configured: ", state.enabled);
    BackgroundGeolocation.sync();
});

Expected Behavior

In backend when the api is called, i was expecting the extras object that i am updating in the config.

Actual Behavior

extras is blank like {};

Steps to Reproduce

  1. Just make the config ready without the extras.
  2. After its ready display your UI and start the schedule with above code.
  3. Monitor the backend api.
  4. Its not having the updated extras object.

Context

I was trying to start the schedule with updated extras object.

Debug logs

Logs No log i have printed. ``` PASTE_YOUR_LOGS_HERE ```

mahesh-agrawal-616 avatar Jun 03 '22 11:06 mahesh-agrawal-616

This problem is always related to having existing location records in the plugin's database attempted to be posted and your server is returning an error, causing the plugin to keep posting that existing first record over and over.

Observe the plugin's logs with adb logcat *:S TSLocationManager:V ReactNativeJS:V ReactNative:V

extras are not updated for existing records in the SQLite database. They are modified only for the next records inserted.

I just did a test. On a button-click, I increment a variable clicks++.

this.clicks++
await BackgroundGeolocation.setConfig({
  extras: {
    clicks: this.clicks
  }
});
// Request a location to invoke an HTTP request
BackgroundGeolocation.getCurrentPosition();

Observing the data on the server, I see extras.clicks incrementing.

Plugin version: 3.9.3

That version dates back to 2020-11-06. I doubt there was a problem with extras in that version, but it is really old and won't support latest Android 12.

christocracy avatar Jun 03 '22 13:06 christocracy

I have tried multiple times by deleting the build from the phone as well. Still the result is same and i am not able to get the updated extras. By the way, i am doing startSchedule after doing setConfig.

mahesh-agrawal-616 avatar Jun 03 '22 16:06 mahesh-agrawal-616

See wiki Debugging. Configure for verbose logging. call .emailLog and attach the received log file here.

christocracy avatar Jun 03 '22 18:06 christocracy

this.clicks++
await BackgroundGeolocation.setConfig({
  extras: {
    clicks: this.clicks
  }
});
// Request a location to invoke an HTTP request
BackgroundGeolocation.getCurrentPosition();
Screen Shot 2022-06-03 at 2 52 21 PM Screen Shot 2022-06-03 at 2 52 54 PM

christocracy avatar Jun 03 '22 18:06 christocracy

Let me check the same way. Will confirm.

mahesh-agrawal-616 avatar Jun 04 '22 03:06 mahesh-agrawal-616

And provide your log file from .emailLog() here.

I’m sure it’s got http errors from your server from the plugin trying over and over again to post already inserted records from before you updated your extras.

existing records inserted into the plug-in’s database are immutable — they will not have their extras updated.

christocracy avatar Jun 04 '22 15:06 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 Sep 21 '22 03:09 stale[bot]