capacitor-background-geolocation: Scheduler Fails to Start On iOS

Your Environment

  • Plugin version: 4.4.3
  • Platform: iOS
  • Device OS version: 15.6.1, 16.0
  • Device manufacturer / model: Apple iPhone
  • XCode version: 13.1
  • Capacitor info (npx cap doctor)
๐Ÿ’Š	Capacitor Doctor	๐Ÿ’Š

Latest Dependencies:

  @capacitor/cli: 4.3.0
  @capacitor/core: 4.3.0
  @capacitor/android: 4.3.0
  @capacitor/ios: 4.3.0

Installed Dependencies:

  @capacitor/cli: 3.1.2
  @capacitor/core: 3.8.0
  @capacitor/android: 3.1.2
  @capacitor/ios: 3.1.2

[success] iOS looking great! ๐Ÿ‘Œ
[success] Android looking great! ๐Ÿ‘Œ
  • Plugin config provided to #ready:
/**
   * This is the config for the TransistorSoft Background Geolocation.
   * On **First Install** and use this is the value that gets set within the plugin.
   * On **Subsequent Launches** of the app, this will override configuration (for the properties with values provided) that was set on first use.
   *
   * @type {Config}
   * @private
   */
  private readonly INIT_CONFIG: Config = {
    // Plugin Config
    reset: false,                  // <-- Setting to false allows the BackgroundGeolocation to re-apply its persisted configuration (Makes it not clear out schedule and other config data when ready is called). We handle updating the config with the values set in INIT_CONFIG after ready. So that if INIT_CONFIG values change, the config is set without resetting peristed values.
    // Location Settings
    desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
    distanceFilter: 10,
    // Activity Recognition
    stopTimeout: 1,
    // Application config
    stopOnTerminate: false,        // <-- Setting to false allows the background-service to continue tracking when user closes the app.
    startOnBoot: true,             // <-- Auto start tracking when device is powered-up.
    foregroundService: true,       // <-- Help Android from killing the app if running
    // Schedule Tracking
    // schedule                    // <-- Do not set `schedule` property (even as undefined), so that on ready we do not overwrite any existing schedules from previous launch
    scheduleUseAlarmManager: true, // <-- Force the Android scheduler to use AlarmManager (more precise) instead of JobScheduler
    // HTTP / SQLite config
    batchSync: false,              // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
    autoSync: true,                // <-- [Default: true] Set true to sync each location to server as it arrives.
    headers: {},                   // <-- HTTP Headers
    params: {},                    // <-- Optional HTTP params append to each HTTP request
    extras: {},                    // <-- Optional meta-data appended to each recorded location.
    maxDaysToPersist: 3,           // <-- Maximum number of days to persist offline/unsuccessfully sent location data
    // Location Notification
    notification: {
      channelName: 'Driver Location Tracking',
      smallIcon: "drawable/location_notification_icon"
    },
    // Permissions
    backgroundPermissionRationale: {
      title: 'Location Services Required',
      message: `Enable location permission, and set to {backgroundPermissionOptionLabel}. This is required so that the app can track your location during a trip.`
    },
    // iOS will prompt for location permission we want.
    locationAuthorizationRequest: 'Always',
    disableLocationAuthorizationAlert: true // We handle routing the user to the settings page for both ios and android
  } as const; // as const allows the internal values to be unmodifiable as well.

Expected Behavior

  1. Set Schedule in config
    • Done by getting the current state, and updating the schedule field/property
    • Wait for promise to resolve
  2. Call startSchedule
    • Await for promise to resolve
  3. Check that the returned state from the resolved startSchedule call actually enabled the scheduler.
  4. Should Succeed Every Time

Actual Behavior

  1. Set Schedule in config
    • Done by getting the current state, and updating the schedule field/property
    • Wait for promise to resolve
  2. Call startSchedule
    • Await for promise to resolve
  3. Check that the returned state from the resolved startSchedule call actually enabled the scheduler.
  4. Difference: schedulerEnabled is false!

Context

Trying to set a schedule to include an item from the current date and time to today at 23:59 Local time and then start the scheduler.

This only ever fails on iOS, and does not fail every single time.

The times when this does fail, the transistorsoft logs show 400 request errors (from sending data to our server to save).

Debug logs

Our app logs right before failure (Newest -> Oldest)
(App ID: 195)
September 20, 2022 at 7:55:08 AM GMT-4: Background Geolocation: Schedule Started. Current State: {"logLevel":5,"disableStopDetection":false,"url":"removed","disableAutoSyncOnCellular":false,"geofenceInitialTriggerEntry":true,"desiredAccuracy":-1,"debug":false,"maxRecordsToPersist":-1,"pausesLocationUpdatesAutomatically":true,"desiredOdometerAccuracy":100,"useSignificantChangesOnly":false,"stationaryRadius":25,"didLaunchInBackground":true,"maxDaysToPersist":3,"httpRootProperty":"location","isMoving":true,"stopOnStationary":false,"maxBatchSize":-1,"isFirstBoot":false,"enableTimestampMeta":false,"autoSyncThreshold":0,"geofenceTemplate":"","minimumActivityRecognitionConfidence":70,"lastLocationAuthorizationStatus":3,"locationAuthorizationRequest":"Always","disableLocationAuthorizationAlert":true,"locationTemplate":"","enabled":true,"batchSync":false,"didRequestUpgradeLocationAuthorization":false,"locationsOrderDirection":"ASC","trackingMode":1,"distanceFilter":10,"showsBackgroundLocationIndicator":false,"stopAfterElapsedMinutes":-1,"schedule":["2022-09-20-07:55 2022-09-20-23:59"],"schedulerEnabled":false,"autoSync":true,"stopDetectionDelay":0,"iOSHasWarnedLocationServicesOff":false,"stopOnTerminate":false,"elasticityMultiplier":1,"logMaxDays":3,"heartbeatInterval":60,"persistMode":2,"locationTimeout":60,"locationAuthorizationAlert":{"titleWhenOff":"Location services are off","settingsButton":"Settings","instructions":"To use background location, you must enable '{locationAuthorizationRequest}' in the Location Services settings","cancelButton":"Cancel","titleWhenNotEnabled":"Background location is not enabled"},"extras":{},"method":"POST","preventSuspend":false,"startOnBoot":true,"stopTimeout":1,"activityRecognitionInterval":10000,"odometer":3215618.3641011217,"headers":{},"disableMotionActivityUpdates":false,"geofenceProximityRadius":2000,"params":{},"disableElasticity":false,"activityType":1,"didDeviceReboot":true,"httpTimeout":60000} (App ID: 195)

September 20, 2022 at 7:55:08 AM GMT-4: Background Geolocation: Starting Schedule. Current State: {"logLevel":5,"disableStopDetection":false,"url":"removed","disableAutoSyncOnCellular":false,"geofenceInitialTriggerEntry":true,"desiredAccuracy":-1,"debug":false,"maxRecordsToPersist":-1,"pausesLocationUpdatesAutomatically":true,"desiredOdometerAccuracy":100,"useSignificantChangesOnly":false,"stationaryRadius":25,"didLaunchInBackground":true,"maxDaysToPersist":3,"httpRootProperty":"location","isMoving":true,"stopOnStationary":false,"maxBatchSize":-1,"isFirstBoot":false,"enableTimestampMeta":false,"autoSyncThreshold":0,"geofenceTemplate":"","minimumActivityRecognitionConfidence":70,"lastLocationAuthorizationStatus":3,"locationAuthorizationRequest":"Always","disableLocationAuthorizationAlert":true,"locationTemplate":"","enabled":true,"batchSync":false,"didRequestUpgradeLocationAuthorization":false,"locationsOrderDirection":"ASC","trackingMode":1,"distanceFilter":10,"showsBackgroundLocationIndicator":false,"stopAfterElapsedMinutes":-1,"schedule":["2022-09-20-07:55 2022-09-20-23:59"],"schedulerEnabled":false,"autoSync":true,"stopDetectionDelay":0,"iOSHasWarnedLocationServicesOff":false,"stopOnTerminate":false,"elasticityMultiplier":1,"logMaxDays":3,"heartbeatInterval":60,"persistMode":2,"locationTimeout":60,"locationAuthorizationAlert":{"titleWhenOff":"Location services are off","settingsButton":"Settings","instructions":"To use background location, you must enable '{locationAuthorizationRequest}' in the Location Services settings","cancelButton":"Cancel","titleWhenNotEnabled":"Background location is not enabled"},"extras":{},"method":"POST","preventSuspend":false,"startOnBoot":true,"stopTimeout":1,"activityRecognitionInterval":10000,"odometer":3215618.3641011217,"headers":{},"disableMotionActivityUpdates":false,"geofenceProximityRadius":2000,"params":{},"disableElasticity":false,"activityType":1,"didDeviceReboot":true,"httpTimeout":60000} (App ID: 195)

September 20, 2022 at 7:55:08 AM GMT-4: Background Geolocation: Start Schedule Called (App ID: 195)

September 20, 2022 at 7:55:08 AM GMT-4: Background Geolocation: Add Schedule => Adding: "2022-09-20-07:55 2022-09-20-23:59" (App ID: 195)

September 20, 2022 at 7:55:08 AM GMT-4: Background Geolocation: Add Schedule Called (App ID: 195)

September 20, 2022 at 7:55:08 AM GMT-4: Background Geolocation: Clearing Schedule (App ID: 195)

September 20, 2022 at 7:55:08 AM GMT-4: Background Geolocation: Clear Schedule Called (App ID: 195)
TransistorSoft Logs (5 Minutes of logs before error -> Time of Error)

Please see attached file, as github didnโ€™t allow creation of the ticket with the logs inline (Comment is too long (maximum is 65536 characters)) transistorsoft-bg-geolocation.log

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

This has been out in our production environment for some time now and we can confirm that the issue is fully resolved. Thank you so much for looking into and fixing this problem!

Iโ€™ve reproduced this and discovered the problem.

Fix is released to 4.11.2