Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS schedule tracking not automatically turning off in background #1967

Open
albertstill opened this issue Mar 17, 2024 · 3 comments
Open

iOS schedule tracking not automatically turning off in background #1967

albertstill opened this issue Mar 17, 2024 · 3 comments
Labels

Comments

@albertstill
Copy link

Your Environment

  • Plugin version:
  • Platform: iOS
  • OS version: 17.3.1
  • Device manufacturer / model: iPhone 13 Pro
  • React Native version (react-native -v): 0.71.16
  • Plugin config
// 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

  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
Copy link
Member

christocracy commented Mar 17, 2024

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
Copy link
Member

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.

Copy link

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

@github-actions github-actions bot added the stale label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants