Skip to content

[Help Wanted]: stopAfterElapsedMinutes is not working #2446

@safwanchundakkadan

Description

@safwanchundakkadan

Required Reading

  • Confirmed

Plugin Version

4.19.3

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

iphone 16 pro,iphone 17 pro,samsung galaxy s25 ultra

Device operating-systems(s)

iOS 26.2,Android 13

React Native / Expo version

0.81.4

What do you require assistance about?

In my code I attempted to stop tracking using the ‘stopAfterElapsedMinutes’ function but it is not working. I require a fully functional solution to stop tracking at the end of a shift. The workflow is that when an employee clicks the check-in button the tracking begins and stops when they click the check-out button. However, if an employee forgets to check out I want to stop tracking based on their shift. How can I implement this functionality from the frontend only? I do not want to handle this from the server side. What is the 100% working method from the frontend code that will function even if the phone restarts, the app is killed or is in the background?

[Optional] Plugin Code and/or Config

let configDefault = {
    disableMotionActivityUpdates: false,
    activityRecognitionInterval: 30000,
    stopAfterElapsedMinutes: Boolean(end_of_tracking)
      ? stopAfterElapsedMinutes
      : 720,
    stopTimeout: 5,

    distanceFilter: 50,
    desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
    stationaryRadius: 50,

    disableElasticity: true,

    foregroundService: true,
    notification: {
      title: 'Live tracking enabled',
      text: 'Location service activated',
      smallIcon: 'drawable/ic_stat_onesignal_default',
      priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_HIGH,
      sticky: true,
    },

    isMoving: true,
    debug: false,
    // logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
    disableProviderChangeRecord: true,

    showsBackgroundLocationIndicator: true,
    pausesLocationUpdatesAutomatically: false,

    locationAuthorizationRequest: 'Always',
    backgroundPermissionRationale: {
      title: 'Background Location Access',
      message:
        'As per the configurations, you need to enable the background location for the check-in/out. You can enable it by selecting {backgroundPermissionOptionLabel} from the location permission',
      positiveAction: 'Change to {backgroundPermissionOptionLabel}',
      negativeAction: 'Cancel',
    },

    maxDaysToPersist: 1,
    stopOnTerminate: false,
    startOnBoot: true,
    enableHeadless: true,
    preventSuspend: true,

    url: `${endpoint}/geolocation/api/v2/real-time-tracking/`,
    headers: {
      Accept: 'application/json',
      'X-DTS-SCHEMA': `https://${domain}`,
      appVersion: appVersion,
      uniqueDeviceId: uniqueId,
      origin: `https://${domain}`,
    },
    autoSync: true,
    locationsOrderDirection: 'ASC',

    maxBatchSize: 5,
    batchSync: true,
    autoSyncThreshold: 5,

    params: {
      employeeId: id,
      employeeCode: empCode,
    },

    authorization: {
      strategy: 'JWT',
      accessToken: token,
      refreshToken: refreshToken,
      refreshUrl: `${endpoint}/api/token/refresh-with-expiry/`,
      refreshPayload: {
        refresh: '{refreshToken}',
      },
      refreshHeaders: {
        'Content-Type': 'application/json',
        'X-DTS-SCHEMA': `https://${domain}`,
      },
      expires: 3600,
    },

    allowIdenticalLocations: false,
    scheduleUseAlarmManager: true,
  };

[Optional] Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions