transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.63k stars 425 forks source link

"When in use" on iOS stops tracking [edited] #1441

Closed ironmanromeo closed 2 years ago

ironmanromeo commented 2 years ago

Your Environment

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 ] ✅ 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] ```
ironmanromeo commented 2 years ago

the only difference appears to be logLevel

christocracy commented 2 years ago

My demo apps for Flutter and Capacitor are complex, with full map.

I will add mapping to my new demo app.

ironmanromeo commented 2 years ago

Right: interesting consideration.

christocracy commented 2 years ago

I haven't tested it yet, but I think I see the issue in HelloWorldApp.tsx. I decided to boot the app in the Simulator and have a look at the memory / CPU usage while simulating location with Freeway Drive. After about 5 minutes, it goes off-the-charts.

Memory

Screen Shot 2022-02-08 at 5 13 10 PM

CPU

Screen Shot 2022-02-08 at 5 13 46 PM

Try this: In your bggeolocation-demo-issue repo, disable this line. That will prevent the onLocation event-handler from adding a JSON record of each location to the list.

Here's what the memory/cpu profile looks like without adding JSON for each record the the ReactNative UI:

Memory

Screen Shot 2022-02-08 at 4 59 34 PM

CPU

Screen Shot 2022-02-08 at 5 00 20 PM
christocracy commented 2 years ago

distanceFilter: 0 of course causes an insane amount of records to be added to the UI in a short period of time.

ironmanromeo commented 2 years ago

Can this be a problem in SQLite?

ironmanromeo commented 2 years ago

You should not use .map. for UI elements. Never! Try FlatList.

christocracy commented 2 years ago

Can this be a problem in SQLite?

If you’re talking about the plug-in’s SQLIte, no. Notice the flat memory / cpu response when I disable the plugin updating the UI. The plugin has been doing this same thing with SQLite since 2013.

You should not use .map. for UI elements. Never! Try FlatList.

I’m basically a noob when it comes to React UI.

disable the line I mentioned in your demo app and go outside for a test.

ironmanromeo commented 2 years ago

I will, but what happens is obvious: memory spikes because .map continues to create Views as the array grows and at some point the system is no longer able to handle a large number of objects. FlatList instead uses a FIFO mechanism whereby only the views that are on a screen are created and as the last cell that disappears from the view is reused by re-inserting it from the top. They are typically 5 or 6 views instead of thousands. What I see in the simulator is absolutely obvious. I edit the page with the FlatList before going out and put it here.

christocracy commented 2 years ago

I’m not concerned about the list.

I’m concerned about finding the reason your app stops tracking after 5min.

In your own app, you’re likely doing something similar, accumulating a large amount of data in memory. Eg: Markers on a map.

ironmanromeo commented 2 years ago

I save as you the data in the DB (SQLite), but in fact I have not checked if the UI compromises the memory. Following your advice I will postpone the UI update when the training is finished.

ironmanromeo commented 2 years ago

This could help: https://reactnative.dev/docs/appstate

christocracy commented 2 years ago

Ok, I took out your demo app with onLocation prevented from adding records to the list. About one hour: tracking was successful.

This case is closed. The problem was client javascript consuming too much memory and the OS suspending the app to save the phone from the app consuming all the device resources.

There was no issue with the plugin.

christocracy commented 2 years ago

@diretur You're being blocked.

This is 100% not a plugin issue. The plugin's responsibility ends once its events are executed. Everything beyond that is your own app's responsibility.