capacitor-background-geolocation: [Bug]: iOS ProviderChange Event is not getting posted to HTTP URL

Required Reading

  • Confirmed

Plugin Version

6.0.3

Cap Doctor

Installed Dependencies:

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

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

iPhone

Device operating-systems(s)

All iOS Versions

What happened?

When the user disables location or changes location permission, the providerChange event happens but that does not get posted to the HTTP URL.

This JS handle for onProviderChange is getting invoked, but the HTTP endpoint does not receive an event with type “providechange”. This happens only on iOS. On Android, the event is getting posted to the HTTP endpoint

BackgroundGeolocation.onProviderChange((provider) => { this.logger.log(Location Tracking: Provider Change - ${JSON.stringify(provider)}); this.geoLocationProviderStatus = provider; this.triggerRefreshPermissionStatus(); const status = this.getLocationPermissionStatus(); if(!status?.allow){ this.pushService.createLocalNotification(“Location Permission Not Granted”, status.message, null) } });

Plugin Code and/or Config

const config: Config = {
            desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
            locationAuthorizationRequest: 'Always',
            backgroundPermissionRationale: {
                
            },
            locationAuthorizationAlert: {
              
            },
            logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
            debug: !environment.production,// <-- enable debug sounds/notifications
            url: environment.dataStreamApiUrl + '/api/XXXX',
            autoSync: true,
            autoSyncThreshold: 2,
            batchSync: true,
            maxBatchSize: 10,
            httpRootProperty: 'location',
            params: payloadParams,
            locationsOrderDirection: "ASC",
            maxDaysToPersist: 1,
            stopOnTerminate: false,
            enableHeadless: true,
            notification: {
                text: "Location services are running in the background",
                priority: BackgroundGeolocation.NOTIFICATION_PRIORITY_DEFAULT,
            }
        }
        return new Promise((resolve, reject) => {
            BackgroundGeolocation.setConfig(config).then((state) => {
                resolve(true);
            }).catch(error => {
                resolve(false);
            });
        });

Relevant log output

║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/33 | isMoving: 0
╚═══════════════════════════════════════════════════════════
🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 2
🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 2
🔵-[PolygonGeofencingService locationManager:didChangeAuthorizationStatus:] 2
🔵-[LocationManager locationManager:didChangeAuthorizationStatus:] 2
🔵-[BackgroundTaskManager locationManager:didChangeAuthorizationStatus:] 2
ℹ️-[TSConfig persist]
🔵-[TSLocationManager locationManager:didChangeAuthorizationStatus:] status 2
⚡️  TO JS {"accuracyAuthorization":1,"network":true,"enabled":false,"gps":true,"status":2}

╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0
╚═══════════════════════════════════════════════════════════

╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0
╚═══════════════════════════════════════════════════════════

╔═══════════════════════════════════════════════════════════
║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0
╚═══════════════════════════════════════════════════════════
ℹ️+[LocationAuthorization run:onCancel:] status: 2

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

Because that’s how I made it.

Carefully read the api docs Config.stopOnTerminate to understand the iOS behaviour after the app is terminated, to understand why tracking is halted until the device moves at least 200 meters.

Also option.extras does not accept the event data of onProviderChange

Options.extras accepts any arbitrary meta-data object.