react-native-background-geolocation: "When in use" on iOS stops tracking [edited]

Your Environment

  • Plugin version: ^4.4.4
  • Platform: Android
  • OS version: 9
  • Device manufacturer / model: Honor View 10 Lite
  • React Native version (react-native -v): react-native-cli: 2.0.1 - react-native: 0.64.3
  • Plugin config
const AndroidSettings = {
    desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
    enableHeadless: true,
    stopOnTerminate: false,  // <-- required for Headless JS
    //preventSuspend: true,
    heartbeatInterval: 60,
    //stopTimeout: 60*10,
    locationAuthorizationRequest: 'WhenInUse',
    debug: false,
    logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
    //transistorAuthorizationToken: token,
    distanceFilter: 10,
    //isMoving:true,
    //pausesLocationUpdatesAutomatically:false,
    //disableStopDetection:true
}

Expected Behavior

It should track in the background with “When in use” privacy

Actual Behavior

After a certain period of time the application stops tracking

Steps to Reproduce

  1. Start the service with BackgroundGeolocation.start();
  2. Turn off the phone screen (leaving the application open in the background)
  3. Walking, running, cycling …
  4. Turn the screen back on and end the service if you have lost track

Context

Being able to create an iOS and Android application that tracks the activity of a person who walks, runs or rides a bicycle both on the road and on dirt roads.

In log file we found that activity tracking stops here: 02-02 14:41:42.583 DEBUG [AbstractService a] ⚙️︎ finish TrackingService [eventCount: 0, sticky: true]

Here I resumed the app: 02-02 14:47:34.370 INFO [LoggerFacade$a a]

we lost tracking from 14:41 to 14:47.

Debug logs

Logs

╔═════════════════════════════════════════════ ║ TSLocationManager version: 3.1.35 (391) ╠═════════════════════════════════════════════ ╟─ HUAWEI JSN-L21 @ 9 (react-native) { "activityRecognitionInterval": 10000, "allowIdenticalLocations": false, "authorization": {}, "autoSync": true, "autoSyncThreshold": 0, "backgroundPermissionRationale": { "title": "Allow {applicationName} to access this device's location even when closed or not in use?", "message": "[CHANGEME] This app collects location data for FEATURE X and FEATURE Y.", "positiveAction": "Change to \"{backgroundPermissionOptionLabel}\"", "negativeAction": "" }, "batchSync": false, "configUrl": "", "debug": false, "deferTime": 0, "desiredAccuracy": -2, "desiredOdometerAccuracy": 100, "disableAutoSyncOnCellular": false, "disableElasticity": false, "disableLocationAuthorizationAlert": false, "disableMotionActivityUpdates": false, "disableStopDetection": false, "distanceFilter": 10, "elasticityMultiplier": 1, "enableHeadless": true, "enableTimestampMeta": false, "extras": {}, "fastestLocationUpdateInterval": -1, "foregroundService": true, "geofenceInitialTriggerEntry": true, "geofenceModeHighAccuracy": false, "geofenceProximityRadius": 1000, "geofenceTemplate": "", "headers": {}, "headlessJobService": "com.transistorsoft.rnbackgroundgeolocation.HeadlessTask", "heartbeatInterval": -1, "httpRootProperty": "location", "httpTimeout": 60000, "isMoving": false, "locationAuthorizationRequest": "WhenInUse", "locationTemplate": "", "locationTimeout": 60, "locationUpdateInterval": 1000, "locationsOrderDirection": "ASC", "logLevel": 5, "logMaxDays": 3, "maxBatchSize": -1, "maxDaysToPersist": 1, "maxRecordsToPersist": -1, "method": "POST", "minimumActivityRecognitionConfidence": 75, "motionTriggerDelay": 0, "notification": { "layout": "", "title": "", "text": "Location Service activated", "color": "", "channelName": "TSLocationManager", "smallIcon": "", "largeIcon": "", "priority": 0, "sticky": false, "strings": {}, "actions": [] }, "params": {}, "persist": true, "persistMode": 2, "schedule": [], "scheduleUseAlarmManager": false, "speedJumpFilter": 300, "startOnBoot": false, "stationaryRadius": 25, "stopAfterElapsedMinutes": 0, "stopOnStationary": false, "stopOnTerminate": false, "stopTimeout": 5, "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking", "url": "", "useSignificantChangesOnly": false, "enabled": false, "schedulerEnabled": false, "trackingMode": 1, "odometer": 11808.599609375, "isFirstBoot": false, "didLaunchInBackground": false, "didDeviceReboot": false } ╔═════════════════════════════════════════════ ║ DEVICE SENSORS ╠═════════════════════════════════════════════ ╟─ ✅ ACCELEROMETER: {Sensor name="accelerometer-bmi160", vendor="BOSCH", version=1, type=1, maxRange=78.4532, resolution=9.576806E-6, power=0.23, minDelay=4000} ╟─ ✅ GYROSCOPE: {Sensor name="bosch-bmi160", vendor="BOSCH", version=1, type=4, maxRange=34.906586, resolution=1.7453292E-5, power=6.1, minDelay=4000} ╟─ ✅ MAGNETOMETER: {Sensor name="mag-akm09918", vendor="akm", version=1001, type=2, maxRange=2000.0, resolution=0.0625, power=6.8, minDelay=10000} ╟─ ✅ SIGNIFICANT_MOTION: {Sensor name="significant Motion", vendor="huawei", version=1, type=17, maxRange=2.14748365E9, resolution=1.0, power=0.23, minDelay=-1} ╚═════════════════════════════════════════════

╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=26 et=+3d1h28m29s452ms alt=261.0 vel=0.60704195 bear=312.5772 vAcc=1 sAcc=??? bAcc=???], age: 108ms, time: 1643809295463

02-02 14:41:35.580 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:41:35.582 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 8.946
02-02 14:41:35.584 DEBUG [TSLocationManager incrementOdometer] Odometer: 11340.667
02-02 14:41:35.586 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:41:35.609 INFO [b persist] 
  ✅  INSERT: 22397d68-6df4-437d-9cad-dcb52aa3f427
02-02 14:41:37.582 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:41:37.585 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=30 et=+3d1h28m31s490ms alt=261.0 vel=0.85510886 bear=317.46118 vAcc=1 sAcc=??? bAcc=???], age: 81ms, time: 1643809298000

02-02 14:41:37.587 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:41:37.588 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 9.159
02-02 14:41:37.591 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:41:37.597 INFO [b persist] 
  ✅  INSERT: 24fbbe45-5946-42d5-8ddb-b7d8570cc698
02-02 14:41:38.848 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:41:38.852 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=23 et=+3d1h28m32s766ms alt=261.0 vel=0.94061583 bear=328.5504 vAcc=1 sAcc=??? bAcc=???], age: 73ms, time: 1643809298777

02-02 14:41:38.857 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:41:38.857 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:41:38.858 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 9.319
02-02 14:41:38.859 DEBUG [TSLocationManager incrementOdometer] Odometer: 11374.249
02-02 14:41:38.900 INFO [b persist] 
  ✅  INSERT: 258158e7-aa0a-45c7-97b8-12ba94fd6021
02-02 14:41:39.997 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:41:40.003 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=18 et=+3d1h28m33s908ms alt=261.0 vel=1.0325823 bear=337.04288 vAcc=1 sAcc=??? bAcc=???], age: 82ms, time: 1643809299920

02-02 14:41:40.007 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:41:40.008 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 9.062
02-02 14:41:40.015 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:41:40.023 INFO [b persist] 
  ✅  INSERT: 8a1604c0-b988-48d1-86cf-ef9436fca905
02-02 14:41:42.570 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:41:42.578 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=14 et=+3d1h28m36s477ms alt=261.0 vel=1.1349927 bear=343.4294 vAcc=1 sAcc=??? bAcc=???], age: 83ms, time: 1643809303000

02-02 14:41:42.583 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:41:42.583 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:41:42.589 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 9.749
02-02 14:41:42.593 DEBUG [TSLocationManager incrementOdometer] Odometer: 11400.761
02-02 14:41:42.625 INFO [b persist] 
  ✅  INSERT: e9772b4f-bdc9-49bb-9ba0-e72bb8e623c4
02-02 14:47:34.370 INFO [LoggerFacade$a a] 
╔═════════════════════════════════════════════
║ TSLocationManager version: 3.1.35 (391)
╠═════════════════════════════════════════════
╟─ HUAWEI JSN-L21 @ 9 (react-native)
{
  "activityRecognitionInterval": 10000,
  "allowIdenticalLocations": false,
  "authorization": {},
  "autoSync": true,
  "autoSyncThreshold": 0,
  "backgroundPermissionRationale": {
    "title": "Allow {applicationName} to access this device's location even when closed or not in use?",
    "message": "[CHANGEME] This app collects location data for FEATURE X and FEATURE Y.",
    "positiveAction": "Change to \"{backgroundPermissionOptionLabel}\"",
    "negativeAction": ""
  },
  "batchSync": false,
  "configUrl": "",
  "debug": false,
  "deferTime": 0,
  "desiredAccuracy": -2,
  "desiredOdometerAccuracy": 100,
  "disableAutoSyncOnCellular": false,
  "disableElasticity": false,
  "disableLocationAuthorizationAlert": false,
  "disableMotionActivityUpdates": false,
  "disableStopDetection": false,
  "distanceFilter": 10,
  "elasticityMultiplier": 1,
  "enableHeadless": true,
  "enableTimestampMeta": false,
  "extras": {},
  "fastestLocationUpdateInterval": -1,
  "foregroundService": true,
  "geofenceInitialTriggerEntry": true,
  "geofenceModeHighAccuracy": false,
  "geofenceProximityRadius": 1000,
  "geofenceTemplate": "",
  "headers": {},
  "headlessJobService": "com.transistorsoft.rnbackgroundgeolocation.HeadlessTask",
  "heartbeatInterval": -1,
  "httpRootProperty": "location",
  "httpTimeout": 60000,
  "isMoving": true,
  "locationAuthorizationRequest": "WhenInUse",
  "locationTemplate": "",
  "locationTimeout": 60,
  "locationUpdateInterval": 1000,
  "locationsOrderDirection": "ASC",
  "logLevel": 5,
  "logMaxDays": 3,
  "maxBatchSize": -1,
  "maxDaysToPersist": 1,
  "maxRecordsToPersist": -1,
  "method": "POST",
  "minimumActivityRecognitionConfidence": 75,
  "motionTriggerDelay": 0,
  "notification": {
    "layout": "",
    "title": "",
    "text": "Location Service activated",
    "color": "",
    "channelName": "TSLocationManager",
    "smallIcon": "",
    "largeIcon": "",
    "priority": 0,
    "sticky": false,
    "strings": {},
    "actions": []
  },
  "params": {},
  "persist": true,
  "persistMode": 2,
  "schedule": [],
  "scheduleUseAlarmManager": false,
  "speedJumpFilter": 300,
  "startOnBoot": false,
  "stationaryRadius": 25,
  "stopAfterElapsedMinutes": 0,
  "stopOnStationary": false,
  "stopOnTerminate": false,
  "stopTimeout": 5,
  "triggerActivities": "in_vehicle, on_bicycle, on_foot, running, walking",
  "url": "",
  "useSignificantChangesOnly": false,
  "enabled": true,
  "schedulerEnabled": false,
  "trackingMode": 1,
  "odometer": 11400.7607421875,
  "isFirstBoot": false,
  "didLaunchInBackground": false,
  "didDeviceReboot": false
}
02-02 14:47:34.374 INFO [TSConfig print] 
╔═════════════════════════════════════════════
║ DEVICE SENSORS
╠═════════════════════════════════════════════
╟─ ✅  ACCELEROMETER: {Sensor name="accelerometer-bmi160", vendor="BOSCH", version=1, type=1, maxRange=78.4532, resolution=9.576806E-6, power=0.23, minDelay=4000}
╟─ ✅  GYROSCOPE: {Sensor name="bosch-bmi160", vendor="BOSCH", version=1, type=4, maxRange=34.906586, resolution=1.7453292E-5, power=6.1, minDelay=4000}
╟─ ✅  MAGNETOMETER: {Sensor name="mag-akm09918", vendor="akm", version=1001, type=2, maxRange=2000.0, resolution=0.0625, power=6.8, minDelay=10000}
╟─ ✅  SIGNIFICANT_MOTION: {Sensor name="significant Motion", vendor="huawei", version=1, type=17, maxRange=2.14748365E9, resolution=1.0, power=0.23, minDelay=-1}
╚═════════════════════════════════════════════
02-02 14:47:34.382 INFO [BackgroundGeolocation <init>] 
  ✅  Google Play Services: connected (version code:12451000)
02-02 14:47:34.391 DEBUG [HttpService startMonitoringConnectivityChanges] 
  🎾  Start monitoring connectivity changes
02-02 14:47:34.398 DEBUG [TSLocationManager$d run] 
  ℹ️  Load last odometer location: Location[TSLocationManager 46******,9****** hAcc=14 t=?!? et=?!? vAcc=??? sAcc=??? bAcc=???]
02-02 14:47:34.399 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:47:34.409 DEBUG [HttpService a] 
╔═════════════════════════════════════════════
║ 📶  Connectivity change: connected? true
╠═════════════════════════════════════════════

02-02 14:47:34.410 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=19 et=+3d1h34m27s931ms alt=263.6999816894531 vAcc=1 sAcc=??? bAcc=???], age: 467ms, time: 1643809653942

02-02 14:47:34.411 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:47:34.412 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 19.369
02-02 14:47:34.412 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:47:34.413 INFO [BackgroundGeolocation d] 
  🎾  Start monitoring location-provider changes
02-02 14:47:34.423 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:34.424 DEBUG [b prune] 
  ℹ️  PRUNE -1 days
02-02 14:47:34.427 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:34.446 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:34.447 INFO [ActivityRecognitionService b] 
  🎾  Start motion-activity updates
02-02 14:47:34.449 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: connectivitychange
02-02 14:47:34.472 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:34.472 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:34.474 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: providerchange
02-02 14:47:34.478 INFO [b persist] 
  ✅  INSERT: e31cc435-c79d-48f8-a526-8c8e3cc9062d
02-02 14:47:34.489 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:34.490 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:47:35.330 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 1
02-02 14:47:35.335 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 2
02-02 14:47:35.336 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 3
02-02 14:47:39.110 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:47:39.115 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=29 et=+3d1h34m33s21ms alt=263.79998779296875 vel=1.5546426 bear=315.6494 vAcc=1 sAcc=??? bAcc=???], age: 80ms, time: 1643809659617

02-02 14:47:39.117 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:47:39.119 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 24.017
02-02 14:47:39.124 INFO [TSScheduleManager oneShot] 
  ⏰ Scheduled OneShot: STOP_TIMEOUT in 300000ms (jobID: 2059034116)
02-02 14:47:39.140 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:47:39.143 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:39.144 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:47:39.146 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 4
02-02 14:47:39.150 INFO [b persist] 
  ✅  INSERT: 7bce9922-72e8-46bc-b626-cc84f296002e
02-02 14:47:40.840 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 1
02-02 14:47:40.842 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 2
02-02 14:47:40.855 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 3
02-02 14:47:40.891 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 4
02-02 14:47:41.094 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:47:41.099 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=24 et=+3d1h34m35s20ms alt=263.79998779296875 vel=0.0 bear=90.0 vAcc=1 sAcc=??? bAcc=???], age: 66ms, time: 1643809661616

02-02 14:47:41.101 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:47:41.101 INFO [TrackingService b] 
  ℹ️  Distance from stoppedAtLocation: -41.443478
02-02 14:47:41.102 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:47:41.102 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 23.832
02-02 14:47:41.134 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:41.135 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:47:41.138 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 5
02-02 14:47:41.151 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 5
02-02 14:47:41.156 INFO [b persist] 
  ✅  INSERT: 57dd8f4f-381c-40f8-bd3c-a3abfd4d2d99
02-02 14:47:48.700 DEBUG [AbstractService a] 
  🎾  ActivityRecognitionService [eventCount: 1]
02-02 14:47:48.716 DEBUG [ActivityRecognitionService a] 
  🚘 ️DetectedActivity [type=UNKNOWN, confidence=40]
02-02 14:47:48.762 DEBUG [AbstractService a] ⚙️︎  finish ActivityRecognitionService [eventCount: 0, sticky: false]
02-02 14:47:48.863 DEBUG [AbstractService a] 
  🎾  ActivityRecognitionService [eventCount: 1]
02-02 14:47:48.879 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:48.881 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: activitychange
02-02 14:47:48.881 INFO [HeartbeatService c] 
  🔴  Stop heartbeat
02-02 14:47:48.884 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 6
02-02 14:47:48.898 INFO [TSScheduleManager cancelOneShot] 
  ⏰ Cancel OneShot: STOP_TIMEOUT
02-02 14:47:48.913 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 6
02-02 14:47:48.923 DEBUG [c h] 
  ℹ️  LocationAuthorization: Permission granted
02-02 14:47:48.932 INFO [TrackingService a] 
  🔵  setPace: true → true
02-02 14:47:48.933 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:47:48.934 INFO [ActivityRecognitionService a] 
╔═════════════════════════════════════════════
║ Motion Transition Result
╠═════════════════════════════════════════════
╟─ 🎾  ENTER: walking
╚═════════════════════════════════════════════
02-02 14:47:48.935 DEBUG [AbstractService a] ⚙️︎  finish ActivityRecognitionService [eventCount: 0, sticky: false]
02-02 14:47:48.939 INFO [TrackingService h] 
╔═════════════════════════════════════════════
║ TrackingService motionchange: true
╠═════════════════════════════════════════════

02-02 14:47:48.941 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:47:49.196 DEBUG [AbstractService onDestroy] 
  🔴  ActivityRecognitionService destroyed
02-02 14:47:49.489 DEBUG [AbstractService a] 
  🎾  LocationRequestService [eventCount: 1]
02-02 14:47:49.498 INFO [LocationRequestService b] 
╔═════════════════════════════════════════════
║ motionchange LocationResult: 1
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=22 et=+3d1h34m43s386ms alt=263.6999816894531 vel=0.002440385 bear=90.00043 vAcc=1 sAcc=??? bAcc=???], age: 97ms, time: 1643809670001

02-02 14:47:49.529 INFO [TSLocationManager onSingleLocationResult] 
  🔵  Acquired motionchange position, isMoving: true
02-02 14:47:49.530 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 22.828
02-02 14:47:49.542 INFO [TSLocationManager requestLocationUpdates] 
  🎾  Location-services: ON
02-02 14:47:49.546 INFO [TSLocationManager requestLocationUpdates] 
  🎾  Location-services: ON
02-02 14:47:49.547 DEBUG [TSConfig translateDesiredAccuracy] translateDesiredAccuracy (true): -2
02-02 14:47:49.548 DEBUG [AbstractService a] ⚙️︎  finish LocationRequestService [eventCount: 0, sticky: false]
02-02 14:47:49.561 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:49.562 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:47:49.564 DEBUG [LocationRequestService b] SingleLocationRequest 1 isFinished? true
02-02 14:47:49.566 DEBUG [AbstractService a] ⚙️︎  finish LocationRequestService [eventCount: 0, sticky: false]
02-02 14:47:49.575 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 7
02-02 14:47:49.576 DEBUG [AbstractService onDestroy] 
  🔴  LocationRequestService destroyed
02-02 14:47:49.579 INFO [b persist] 
  ✅  INSERT: c41001e1-cfde-43a8-ae69-85edbd3efcd1
02-02 14:47:49.585 INFO [ActivityRecognitionService b] 
  🎾  Start motion-activity updates
02-02 14:47:49.589 INFO [TSLocationManager removeLocationUpdates] 
  🔴  Location-services: OFF
02-02 14:47:49.596 INFO [TSLocationManager requestLocationUpdates] 
  🎾  Location-services: ON
02-02 14:47:49.598 DEBUG [TSConfig translateDesiredAccuracy] translateDesiredAccuracy (true): -2
02-02 14:47:49.609 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:49.610 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: motionchange
02-02 14:47:49.614 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 8
02-02 14:47:49.616 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 7
02-02 14:47:49.639 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 8
02-02 14:47:49.654 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:47:49.658 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=22 et=+3d1h34m43s386ms alt=263.6999816894531 vel=0.002440385 bear=90.00043 vAcc=1 sAcc=??? bAcc=???], age: 258ms, time: 1643809670001

02-02 14:47:49.659 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:47:49.659 DEBUG [TSLocationManager onLocationResult] 
  ℹ️  IGNORED: same as last location
02-02 14:47:49.662 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:47:56.494 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:47:56.502 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=14 et=+3d1h34m50s405ms alt=263.6999816894531 vel=0.027283628 bear=90.31784 vAcc=1 sAcc=??? bAcc=???], age: 80ms, time: 1643809677001

02-02 14:47:56.504 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:47:56.505 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 21.824
02-02 14:47:56.507 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:47:56.542 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:47:56.543 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:47:56.546 INFO [b persist] 
  ✅  INSERT: 0c604741-673d-4ff5-ae04-4d39b2e98e82
02-02 14:47:56.546 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 9
02-02 14:47:56.554 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 9
02-02 14:48:08.715 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:48:08.722 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=11 et=+3d1h35m2s630ms alt=263.6999816894531 vel=0.79370815 bear=143.9255 vAcc=1 sAcc=??? bAcc=???], age: 76ms, time: 1643809688642

02-02 14:48:08.725 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:48:08.726 DEBUG [TSLocationManager locationIsInvalid] Distance from last location: 11.53847, apparent speed: 0.94391936
02-02 14:48:08.727 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 20.5965
02-02 14:48:08.728 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:48:08.753 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:48:08.753 INFO [b persist] 
  ✅  INSERT: c5989eed-ee7d-47c6-8f21-7d971cccf8ae
02-02 14:48:08.754 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:48:08.763 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 10
02-02 14:48:08.774 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 10
02-02 14:48:09.826 DEBUG [AbstractService a] 
  🎾  ActivityRecognitionService [eventCount: 1]
02-02 14:48:09.830 DEBUG [ActivityRecognitionService a] 
  🚘 ️DetectedActivity [type=UNKNOWN, confidence=40]
02-02 14:48:09.855 DEBUG [AbstractService a] ⚙️︎  finish ActivityRecognitionService [eventCount: 0, sticky: false]
02-02 14:48:10.009 DEBUG [AbstractService a] 
  🎾  ActivityRecognitionService [eventCount: 1]
02-02 14:48:10.015 INFO [ActivityRecognitionService a] 
╔═════════════════════════════════════════════
║ Motion Transition Result
╠═════════════════════════════════════════════
╟─ 🎾  ENTER: walking
╚═════════════════════════════════════════════
02-02 14:48:10.017 DEBUG [AbstractService a] ⚙️︎  finish ActivityRecognitionService [eventCount: 0, sticky: false]
02-02 14:48:10.031 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:48:10.033 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: activitychange
02-02 14:48:10.045 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 11
02-02 14:48:10.048 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 11
02-02 14:48:10.273 DEBUG [AbstractService onDestroy] 
  🔴  ActivityRecognitionService destroyed
02-02 14:48:22.476 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:48:22.480 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=15 et=+3d1h35m16s406ms alt=263.6999816894531 vel=1.1009822 bear=166.76279 vAcc=1 sAcc=??? bAcc=???], age: 61ms, time: 1643809703001

02-02 14:48:22.486 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:48:22.487 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:48:22.490 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 19.369
02-02 14:48:22.513 INFO [b persist] 
  ✅  INSERT: f62e5e24-4785-4293-b6ad-91ee60866c42
02-02 14:48:22.526 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:48:22.527 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:48:22.538 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 12
02-02 14:48:22.545 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 12
02-02 14:48:54.477 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:48:54.483 DEBUG [TrackingService b] 
╔═════════════════════════════════════════════
║ TrackingService: LocationResult
╠═════════════════════════════════════════════
╟─ 📍  Location[fused 46******,9****** hAcc=15 et=+3d1h35m48s403ms alt=263.6999816894531 vel=0.0550971 bear=359.9949 vAcc=1 sAcc=??? bAcc=???], age: 67ms, time: 1643809735001

02-02 14:48:54.489 DEBUG [TSLocationManager onLocationResult] 
╔═════════════════════════════════════════════
║ Process LocationResult
╠═════════════════════════════════════════════

02-02 14:48:54.491 DEBUG [TSLocationManager locationIsInvalid] Distance from last location: 16.639847, apparent speed: 0.52004397
02-02 14:48:54.492 DEBUG [AbstractService a] ⚙️︎  finish TrackingService [eventCount: 0, sticky: true]
02-02 14:48:54.494 DEBUG [TSLocationManager calculateMedianAccuracy] Median accuracy: 17.2325
02-02 14:48:54.513 DEBUG [BackgroundGeolocation isMainActivityActive] NO
02-02 14:48:54.513 DEBUG [HeadlessTask onHeadlessEvent] 💀  event: location
02-02 14:48:54.517 INFO [b persist] 
  ✅  INSERT: 1098b045-1192-4c20-bfcf-178ef9227e67
02-02 14:48:54.521 DEBUG [HeadlessTask$2 onHeadlessJsTaskStart] taskId: 13
02-02 14:48:54.529 DEBUG [HeadlessTask$2 onHeadlessJsTaskFinish] taskId: 13
02-02 14:49:41.499 DEBUG [AbstractService a] 
  🎾  TrackingService [eventCount: 1]
02-02 14:49:41.506 DEBUG [TrackingService b] 




About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 64 (27 by maintainers)

Most upvoted comments

Unfortunately, the problem also manifests itself in the BGGeolocation demo app. We installed it and took a walk of about 3 km. During the journey the application was put into sleep by the system 5 times as you can see from this video.

https://vimeo.com/673216473

Unfortunately we don’t have the logs to show because we followed the suggested settings and didn’t add debug: true. The problem was also found on our app and that you have the log in the previous post.

This is the only modified file in your app: HelloWorldView.tsx

import React from 'react';

import {
  StyleSheet,
  Text,
  View,
  ScrollView,
  SafeAreaView
} from 'react-native';

import {Button, Switch, Icon} from "react-native-elements";

import ENV from "../ENV";
import {COLORS} from "../lib/config";

import BackgroundGeolocation, {Subscription} from "../react-native-background-geolocation";
import {registerTransistorAuthorizationListener} from '../lib/Authorization';

//////
/// A simple implementation of the BackgroundGeolocation plugin.
///
///
const HelloWorldView = ({route, navigation}) => {
  // Keep a list of BackgroundGeolocation event-subscriptions so we can later remove them
  // when the View is destroyed or refreshed during development live-reload.
  const bgGeoEventSubscriptions:Subscription[] = [];

  const {org, username} = route.params;

  /// State.
  const [events, setEvents] = React.useState<any[]>([]);
  const [enabled, setEnabled] = React.useState(false);

  /// Init BackgroundGeolocation when view renders.
  /// Return a function to .removeListeners() When view is removed.
  React.useEffect(() => {
    initBackgroundGeolocation();
    registerTransistorAuthorizationListener(navigation);
    return () => {
      // Remove BackgroundGeolocation event-subscribers when the View is removed or refreshed
      // during development live-reload.  Without this, event-listeners will accumulate with
      // each refresh during live-reload.
      unsubscribe();
    }
  }, []);

  /// Add a toggle <Switch> to top-right toolbar.
  React.useLayoutEffect(() => {
    navigation.setOptions({
      headerRight: () => (
        <Switch onValueChange={onClickEnable} value={enabled} />
      )
    });
  }, [enabled]);

  /// Helper method to push a BackgroundGeolocation subscription onto our list of subscribers.
  const subscribe = (subscription:Subscription) => {
    bgGeoEventSubscriptions.push(subscription);
  }

  /// Helper method to unsubscribe from all registered BackgroundGeolocation event-listeners.
  const unsubscribe = () => {
    bgGeoEventSubscriptions.forEach((subscription:Subscription) => subscription.remove() );
  }

  /// Configure the BackgroundGeolocation plugin.
  const initBackgroundGeolocation = async () => {
    // Listen to events.  Each BackgroundGeolocation event-listener returns a subscription instance
    // with a .remove() method for removing the event-listener.  You should collect a list of these
    // subcribers and .remove() them all when the View is destroyed or refreshed during dev live-reload.
    subscribe(BackgroundGeolocation.onProviderChange((event) => {
      console.log('[onProviderChange]', event);
      addEvent('onProviderChange', event);
    }));

    subscribe(BackgroundGeolocation.onLocation((location) => {
      console.log('[onLocation]', location);
      addEvent('onLocation', location);

    }, (error) => {
      console.warn('[onLocation] ERROR: ', error);
    }));

    subscribe(BackgroundGeolocation.onMotionChange((location) => {
      console.log('[onMotionChange]', location);
      addEvent('onMotionChange', location);
    }));

    subscribe(BackgroundGeolocation.onGeofence((event) => {
      console.log('[onGeofence]', event);
      addEvent('onGeofence', event);
    }));

    subscribe(BackgroundGeolocation.onConnectivityChange((event) => {
      console.log('[onConnectivityChange]', event);
      addEvent('onConnectivityChange', event);
    }));

    subscribe(BackgroundGeolocation.onEnabledChange((enabled) => {
      console.log('[onEnabledChange]', enabled);
      addEvent('onEnabledChange', {enabled: enabled});
    }));

    subscribe(BackgroundGeolocation.onHttp((event) => {
      console.log('[onHttp]', event);
      addEvent('onHttp', event);
    }));

    subscribe(BackgroundGeolocation.onActivityChange((event) => {
      console.log('[onActivityChange]', event);
      addEvent('onActivityChange', event);
    }));

    subscribe(BackgroundGeolocation.onPowerSaveChange((enabled) => {
      console.log('[onPowerSaveChange]', enabled);
      addEvent('onPowerSaveChange', {isPowerSaveMode: enabled});
    }));

    /// Get an authorization token from demo server at tracker.transistorsoft.com
    const token = await BackgroundGeolocation.findOrCreateTransistorAuthorizationToken(org, username, ENV.TRACKER_HOST);

    /// Configure the plugin.
    BackgroundGeolocation.ready({
      debug: false,
      stopTimeout: 60,
      locationAuthorizationRequest: 'WhenInUse',
      distanceFilter: 0,
      pausesLocationUpdatesAutomatically: false,
      disableStopDetection: true
    }).then((state) => {
      BackgroundGeolocation.changePace(true);
      /// Add the current state as first item in list.
      addEvent('Current state', state);
      /// Set the default <Switch> state (disabled)
      setEnabled(state.enabled);
    });



  };

  /// Adds events to List
  const addEvent = (name:string, params:any) => {
    let timestamp = new Date();
    const event = {
      expanded: false,
      timestamp: `${timestamp.getMonth()}-${timestamp.getDate()} ${timestamp.getHours()}:${timestamp.getMinutes()}:${timestamp.getSeconds()}`,
      name: name,
      params: JSON.stringify(params, null, 2)
    }
    setEvents(previous => [...previous, event]);
  }

  /// <Switch> handler to toggle the plugin on/off.
  const onClickEnable = (value:boolean) => {
    (async () => {
      setEnabled(value);
      if (value) {
        await BackgroundGeolocation.start()
        await BackgroundGeolocation.changePace(true)
      } else {
        await BackgroundGeolocation.stop();
      }
    })()
  }

  /// Clear events list.
  const onClickClear = () => {
    setEvents([]);
  }

  /// Execute getCurrentPosition
  const onClickGetCurrentPosition = async () => {
    await BackgroundGeolocation.getCurrentPosition({
      samples: 1,
      extras: {
        getCurrentPosition: true
      }
    });
  }

  return (
    <SafeAreaView style={styles.container}>
      <ScrollView style={styles.events}>
        {events.slice().reverse().map((event, i) => (
          <View style={styles.event} key={i}>
            <View style={styles.header}>
              <Text style={styles.title}>{event.name}</Text>
              <Text style={[styles.title, styles.timestamp]}>{event.timestamp}</Text>
            </View>
            <View key={i}>
              <Text style={styles.params}>{event.params}</Text>
            </View>
          </View>
        ))}
      </ScrollView>

      <View style={styles.bottomToolbar}>
        <View style={{justifyContent:'center'}}>
          <Button
            type="clear"
            onPress={onClickGetCurrentPosition}
            containerStyle={{width: 60}}
            icon={<Icon name='navigate-sharp' type='ionicon' /> }
          />
        </View>
        <View style={{flex: 1}}></View>
        <View style={{justifyContent:'center'}}>
          <Button
            type="clear"
            onPress={onClickClear}
            containerStyle={{width: 60}}
            icon={<Icon name='trash-sharp' type='ionicon' /> }
          />
        </View>
      </View>

    </SafeAreaView>
  );
}

export default HelloWorldView;

const styles = StyleSheet.create({
  container: {
    flexDirection: 'column',
    backgroundColor: COLORS.gold,
    flex: 1
  },
  events: {
    flex: 1,
    //backgroundColor: '#eee'
  },
  event: {
    backgroundColor: '#fff',
    color: '#fff',
    marginBottom: 5,
    borderWidth: 1,
    borderColor: '#000'

  },
  header: {
    backgroundColor: '#000',
    padding: 10,
    flexDirection:'row',
    justifyContent: 'space-between'
  },
  title: {
    flex:1,
    fontWeight: 'bold',
    color: '#fff'
  },
  timestamp: {
    textAlign: 'right',
    fontStyle: 'italic'
  },
  params: {
    fontFamily: 'Courier',
    padding: 5
  },
  bottomToolbar: {
    backgroundColor: COLORS.gold,
    height: 56,
    flexDirection: 'row'
  }
});