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

Schedule is not working as expected in IOS #2075

Open
williamFportillo opened this issue Jun 28, 2024 · 1 comment
Open

Schedule is not working as expected in IOS #2075

williamFportillo opened this issue Jun 28, 2024 · 1 comment

Comments

@williamFportillo
Copy link

williamFportillo commented Jun 28, 2024

Your Environment

  • Plugin version: 4.16.2
  • Platform: iOS
  • OS version: 17.5.1
  • Device manufacturer / model: Iphone 13 pro max
  • React Native version (react-native -v): 0.72.6
  • Plugin config
{
     desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
     distanceFilter: 30,
     stopTimeout: 5,
     debug: false,
     logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
     logMaxDays: 4,
     stopOnTerminate: false,
     startOnBoot: true,
     url: `${API_URL}/v2/location/${userIdParam || userId}`,
     showsBackgroundLocationIndicator: true,
     disableLocationAuthorizationAlert: true,
     maxDaysToPersist: 5,
     maxRecordsToPersist: -1,
     heartbeatInterval: 60,
     preventSuspend: true,
     foregroundService: true,
     disableElasticity: false,
     elasticityMultiplier: 3,
     stopOnStationary: false,
     disableMotionActivityUpdates: false,
     disableProviderChangeRecord: false,
     allowIdenticalLocations: false,
     locationUpdateInterval: 30000,
     fastestLocationUpdateInterval: 30000,
     enableHeadless: true,
     locationsOrderDirection: 'ASC',
     headers: {
       'x-app-secret': envVariables.APP_SECRET_HEADER,
     },
     extras: {
       sessionId: sessionId || uniqueId,
       os: Platform.OS === 'ios' ? 'ios' : 'android',
     },
     locationAuthorizationRequest: 'Always',
     scheduleUseAlarmManager: true,
     stationaryRadius: 250,
     isMoving: true,
}

Expected Behavior

When a schedule is configured and the plug-in is started that schedule will always be running.

Actual Behavior

When a schedule is configured and the plug-in is initialized it starts working as expected. But sometimes after a certain number of days or even hours the schedule stops working. It seems that it does not detect positions or something like that.

To set up a schedule I am currently doing this:

const resetSchedule = async (workdays?: Workdays): Promise<void> => {
    try {
      const schedule = workdays ? getSchedule(workdays) : []; // getSchedule(workdays) returns a string array like this: ["1 00:00-18:00"]
      await BackgroundGeolocation.stopSchedule();
      await BackgroundGeolocation.stop();
      await BackgroundGeolocation.setConfig({
        schedule,
      });
    } catch (error) {
      Alert.alert('Something went wrong while reset schedule');
    }
  };

  const configureSchedule = async ({
    workdays, isTrackingAlwaysActive = isTrackingAlways,
  }: ConfigureScheduleParamsType): Promise<void> => {
    try {
      await resetSchedule(workdays);
      if (toggleStatus && isTrackingAlwaysActive) {
        await BackgroundGeolocation.start();
      }

      if (toggleStatus && !isTrackingAlwaysActive) {
        await BackgroundGeolocation.startSchedule();
      }
    } catch (error) {
      // error
    }
  };

Steps to Reproduce

  1. Configure a schedule with BackgroundGeolocation.setConfig()
  2. Trigger . startSchedule
  3. Left the app in background.

Context

Wednesday, 26 June

The schedule was set up and worked as expected, tracking the day from 00:00 to 18:00.
Screenshot 2024-06-27 at 10 26 23 AM copy

As you can see, the tracking service stopped sending the location at 17:59:34 to the server. The user continued moving but was out of schedule, this behavior is expected.
On the map, you can see an image with the information of the last position sent to the server.

Screenshot 2024-06-27 at 10 30 06 AM copy

Thursday, 27 June

  1. This is the last log from Wednesday, 26 June.
  2. This is the first log for Thursday, 27 June.

Screenshot 2024-06-27 at 11 27 20 AM

The user continued moving, but none of the positions were sent to the server, and we are unable to see them in the logs as well. The last thing we saw on the logs was something related to geofences but we are not using the functionality (just in case).

Screenshot 2024-06-27 at 10 33 17 AM

One thing I noticed in the documentation is that the schedule property receives an array. However, in the logs, the schedule property is using () for the array. Thats something is just happening on iOS and it could just be how the log is being printed, but I thought I'd mention it in case it helps you as well.

Screenshot 2024-06-27 at 10 37 19 AM

Debug logs

Logs

I share with you the logs file because is too large.

Screenshot 2024-06-28 at 12 22 04 PM

background-geolocation.log-14.gz

@williamFportillo williamFportillo changed the title Schedule is not working as expected Schedule is not working as expected in IOS Jun 28, 2024
@christocracy
Copy link
Member

One thing I noticed in the documentation is that the schedule property receives an array. However, in the logs, the schedule property is using () for the array.

This is nothing to worry about. This is merely how an Obj-c NSArray#as_string method prints its contents to the logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants