transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.54k stars 424 forks source link

iOS schedule tracking not automatically turning off in background #1967

Closed albertstill closed 1 week ago

albertstill commented 1 month ago

Your Environment

// In root component's render method useEffect(() => { async function execute() { await BackgroundGeolocation.ready({ reset: false, }); }

execute(); }, []);

...

// in code that handles user setting a day based schedule

async function stopBGSchedule() { const state = await BackgroundGeolocation.stopSchedule(); if (state.enabled) { await BackgroundGeolocation.stop(); } }

// e.g [ '1 00:01-23:59'] function setSchedule(scheduleArray) { await stopBGSchedule();

await BackgroundGeolocation.setConfig({ distanceFilter: 25, stopOnTerminate: false, startOnBoot: true, foregroundService: true,

schedule: scheduleArray,

// Android
notification: {
  title: 'Tern',
  text: 'Detecting when you cycle, walk and run to work.',
  channelName: 'Active commute detection',
  color: BRAND_COLOR,
  smallIcon: 'drawable/ic_stat_ic_notification',
  largeIcon: 'drawable/ic_stat_ic_notification',
  priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_MIN,
},

// http options
url: generateTrackingUrl(userId),
params: {
  device: {
    uuid: deviceInfo.getModel().replace(/[\s.,]/g, '-'),
    model: deviceInfo.getModel(),
    platform: deviceInfo.getSystemName(),
    manufacturer: await deviceInfo.getManufacturer(),
    version: deviceInfo.getSystemVersion(),
    framework: 'ReactNative',
  },
},
autoSyncThreshold: 20,
batchSync: true,
maxBatchSize: 60,

showsBackgroundLocationIndicator: true,

});

await BackgroundGeolocation.startSchedule(); }



## Expected Behavior

The plugin should automatically stop tracking the when the current time falls outside of the users schedule.

## Actual Behavior

The plugin carries on tracking, this is shown to users by the blue pill surrounding the clock in the top left corner of iOS, and location data carries on coming though to the server.

It's not until you open the app and reset the schedule with the same schedule array, it realises the current time is outside of the schedule and turns off.

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1. On a real device, set a schedule that spans the whole of the current day, for example if it was Sunday, set the schedule to `[1 00:01-23:59]`.
2. The plugin goes into an enabled state
3. The morning after (Monday morning), without opening the app, the plugin carries on tracking

Thanks Chris
christocracy commented 1 month ago

I've set up a schedule: ['1 00:00-23:59'] running in the iOS Simulator with Freeway Drive. I will see what happens at midnight tonight.

christocracy commented 1 month ago

Ok, I reproduced this in the simulator by manually modifying my work-station's date/time (you terminate the iOS Simulator after doing so, for it to catch the updated time).

Screenshot 2024-03-19 at 12 17 52 AM

I found the problem and released a fix to v4.15.2.

github-actions[bot] commented 3 weeks ago

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

github-actions[bot] commented 1 week ago

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