transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
656 stars 277 forks source link

iOS 17 blocking requests with a 30-second timeout in the settings. #1435

Closed danillo10 closed 2 months ago

danillo10 commented 2 months ago

Your Environment

Expected Behavior

When it sends multiple requests at the same time, it shouldn't be blocked on iOS, in my case it's every 30 seconds with onHeartbeat or 30 seconds with locationUpdateInterval, but sometimes when it fails to send one request and it sends multiple requests, the iPhone probably blocks the sending of requests.

Actual Behavior

Iphone is blocking the requests

Steps to Reproduce

1. 2. 3. 4.

Context

Debug logs

Logs ``` Background Task 13 ("Called by App, from -[TSHttpService flush:]"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this. ```
christocracy commented 2 months ago

locationUpdateInterval

This is Android-only option.

You need to provide logs from before what you posted.

You mention "heartbeat" but provided no code of what you're doing with it.

danillo10 commented 2 months ago

What would be the ideal configuration for iOS to prevent it from blocking requests?

danillo10 commented 2 months ago

ℹ️-[TSDBLogger db_save] Log committed 🔵-[TSLocationManager onHeartbeat] Heartbeat ⚡️ TO JS {"location":{"uuid":"828D147B-B50D-45E4-976A-DC1CBBDA0E0E","battery":{"level":0.55000001192092896,"is_charging":true},"activity":{"type":"still","confidence":100},"event":"heartbeat","is_moving":false,"timestamp":"2024-02-27T19:00:49.708Z","age":0,"odomete ⚡️ To Native -> BackgroundGeolocation getCurrentPosition 19903765 ⚡️ [log] - Registro - Heartbeat: {"location":{"uuid":"828D147B-B50D-45E4-976A-DC1CBBDA0E0E","battery":{"level":0.550000011920929,"is_charging":true},"activity":{"type":"still","confidence":100},"event":"heartbeat","is_moving":false,"timestamp":"2024-02-27T19:00:49.708Z","age":0,"odometer":2995.4,"extras":{},"coords":{"altitude":873.4,"ellipsoidal_altitude":0,"accuracy":23.7,"altitude_accuracy":1.4,"heading_accuracy":-1,"speed":-1,"latitude":-19.834561376805464,"speed_accuracy":-1,"longitude":-44.01713809980912,"floor":null,"heading":-1}}} 🔵-[TSLocationManager getCurrentPosition:] 🎾-[LocationManager startUpdatingLocation] ON ⚡️ TO JS {"odometer":2995.4000000000001,"battery":{"is_charging":true,"level":0.55000001192092896},"timestamp":"2024-02-27T19:00:12.000Z","extras":{},"is_moving":false,"age":37734,"sample":true,"uuid":"7B6B2E64-4BED-4BE1-ADFA-DA658020DBED","coords":{"ellipsoidal_al ℹ️+[LocationAuthorization run:onCancel:] status: 3

📍<-19.83462667,-44.01698490> +/- 4.41m (speed 0.00 mps / course 113.91) @ 27/02/24, 16:00:12 Brasilia Standard Time

╔═══════════════════════════════════════════════════════════ ║ -[LocationManager locationManager:didUpdateLocations:] Sample 1 of 3 (37734 ms old) ╚═══════════════════════════════════════════════════════════

📍<-19.83462667,-44.01698490> +/- 4.41m (speed 0.00 mps / course 113.91) @ 27/02/24, 16:00:20 Brasilia Standard Time ⚠️-[LocationManager locationManager:didUpdateLocations:] (location-age -29737 ms) ⚡️ To Native -> BackgroundGeolocation setConfig 19903766 ℹ️-[TSConfig persist] ⚡️ TO JS {"disableStopDetection":false,"maxBatchSize":-1,"locationsOrderDirection":"ASC","stopOnStationary":false,"url":"https:\/\/servicos24....","authorization":{"expires":-1,"strategy":"JWT","refreshHeaders":{"Authorization":"Bearer {acce

📍<-19.83456138,-44.01713810> +/- 23.70m (speed -1.00 mps / course -1.00) @ 27/02/24, 16:00:49 Brasilia Standard Time

╔═══════════════════════════════════════════════════════════ ║ -[LocationManager locationManager:didUpdateLocations:] Sample 2 of 3 (17 ms old) ╚═══════════════════════════════════════════════════════════ ⚡️ TO JS {"battery":{"level":0.55000001192092896,"is_charging":true},"age":37782,"extras":{},"odometer":2995.4000000000001,"is_moving":false,"coords":{"accuracy":4.4000000000000004,"heading_accuracy":45.979999999999997,"floor":null,"latitude":-19.834626666288667,"s ⚡️ To Native -> BackgroundGeolocation setConfig 19903767 ℹ️-[TSConfig persist] ⚡️ TO JS {"geofenceProximityRadius":2000,"persistMode":2,"desiredAccuracy":-1,"lastLocationAuthorizationStatus":3,"params":{"veiculo_id":1,"longitude":-44.016984896775348,"user_id":1,"motorista_id":1,"data_hora":"2024-02-27 19:00:12","status":"Viagem finalizada","e

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

📍<-19.83456138,-44.01713810> +/- 23.70m (speed -1.00 mps / course -1.00) @ 27/02/24, 16:00:50 Brasilia Standard Time 🔴-[LocationManager stopUpdatingLocation] OFF

╔═══════════════════════════════════════════════════════════ ║ -[LocationManager locationManager:didUpdateLocations:] Sample 3 of 3 (12 ms old) ╚═══════════════════════════════════════════════════════════ ℹ️-[PolygonGeofencingService setLocation:] Already updating location 🔵-[TSLocationManager calculateMedianLocationAccuracy:] Median location accuracy: 14.1 ℹ️-[PolygonGeofencingService setLocation:] Already updating location ⚡️ TO JS {"uuid":"EDCC4E26-550A-4791-9B9A-EC72F752A2C2","age":38227,"coords":{"altitude_accuracy":4,"latitude":-19.834626666288667,"speed":0,"heading_accuracy":45.979999999999997,"heading":113.91,"speed_accuracy":0.070000000000000007,"longitude":-44.016984896775348 ⚡️ TO JS {"battery":{"is_charging":true,"level":0.55000001192092896},"age":38227,"activity":{"type":"still","confidence":100},"is_moving":false,"coords":{"altitude_accuracy":4,"speed":0,"floor":null,"heading":113.91,"speed_accuracy":0.070000000000000007,"accuracy": ⚡️ To Native -> BackgroundGeolocation setConfig 19903768 ⚡️ To Native -> BackgroundGeolocation setConfig 19903769 ℹ️-[TSConfig persist] ✅-[TSLocationManager persistLocation:]_block_invoke INSERT: EDCC4E26-550A-4791-9B9A-EC72F752A2C2

╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService flush:] ╚═══════════════════════════════════════════════════════════ ✅-[BackgroundTaskManager createBackgroundTask] 8 ✅-[TSHttpService schedulePost] LOCKED: 87B8CF5A-DBF5-47CD-B5AA-86EE5B149EC3 ⚡️ TO JS {"disableStopDetection":false,"maxBatchSize":-1,"locationsOrderDirection":"ASC","stopOnStationary":false,"url":"https:\/\/servicos24...","authorization":{"expires":-1,"strategy":"JWT","refreshHeaders":{"Authorization":"Bearer {acce ℹ️-[TSConfig persist] ⚡️ TO JS {"geofenceProximityRadius":2000,"persistMode":2,"desiredAccuracy":-1,"lastLocationAuthorizationStatus":3,"params":{"veiculo_id":1,"longitude":-44.016984896775348,"user_id":1,"motorista_id":1,"data_hora":"2024-02-27 19:00:12","status":"Viagem finalizada","e ⚡️ To Native -> BackgroundGeolocation getCount 19903770 ⚡️ TO JS {"count":449}

ATS failed system trust Connection 6: system TLS Trust evaluation failed(-9802) Connection 6: TLS Trust encountered error 3:-9802 Connection 6: encountered error(3:-9802) Task <1C1C4F6F-771B-4349-9122-0F42AFFC0021>.<1> HTTP load failed, 0/0 bytes (error code: -1200 [3:-9802]) Task <1C1C4F6F-771B-4349-9122-0F42AFFC0021>.<1> finished with error [-1200] Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo={NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, NSErrorPeerCertificateChainKey=( "<cert(0x13c822a00) s: servicos24horas.com i: R3>", "<cert(0x13c823200) s: R3 i: ISRG Root X1>", "<cert(0x13c814400) s: ISRG Root X1 i: DST Root CA X3>" ), NSErrorClientCertificateStateKey=0, NSErrorFailingURLKey=https://servicos24..., NSErrorFailingURLStringKey=https://servicos24..., NSUnderlyingError=0x283f2f0c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x2800a9360>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9802, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9802, kCFStreamPropertySSLPeerCertificates=( "<cert(0x13c822a00) s: servicos24horas.com i: R3>", "<cert(0x13c823200) s: R3 i: ISRG Root X1>", "<cert(0x13c814400) s: ISRG Root X1 i: DST Root CA X3>" )}}, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <1C1C4F6F-771B-4349-9122-0F42AFFC0021>.<1>" ), _kCFStreamErrorCodeKey=-9802, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <1C1C4F6F-771B-4349-9122-0F42AFFC0021>.<1>, NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x2800a9360>, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made.} ⚠️-[HttpResponse handleResponse] HTTP ERROR: 0


╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService finish:error:] Success: 0 ╚═══════════════════════════════════════════════════════════ ✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 8 OF ( 3, 8 ) ⚡️ TO JS {"success":false,"responseText":"","status":0} ⚡️ [log] - Registro - Http event: {"success":false,"responseText":"","status":0} ⚡️ To Native -> Network getStatus 19903771 ⚡️ TO JS {"connectionType":"wifi","connected":true} ⚡️ [log] - Registro - Http event convite offline: {"id":453,"status":"Viagem finalizada","origem":"belo horizonte / mg","destino":"belo horizonte / MG","material":"cobre","orientacoes":null,"data":"2024-02-27","pedido_id":34,"pedido_detalhe_id":483,"latitude":-19.834626917745762,"longitude":-44.01698456149922,"user_id":1,"motorista_id":1,"veiculo_id":1,"data_hora":"2024-02-27 19:00:06"}

⚡️ [error] - ERROR Error: Uncaught (in promise): [object Boolean]

╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ 🔵-[BackgroundTaskManager startPreventSuspendTimer:] BG time remaining: 20 | Total tasks: 1 🔵-[TSLocationManager onSuspend:] enabled? 1) ℹ️-[TSDBLogger db_save] Log committed 🔵-[BackgroundTaskManager onResume:] Current preventSuspend tasks: 1 🔵-[TSLocationManager onResume:] enabled? 1 ℹ️-[LocationDAO purge:] 1 ℹ️-[TSDBLogger db_save] Log committed

╔═══════════════════════════════════════════════════════════ ║ -[TSHttpService flush:] ╚═══════════════════════════════════════════════════════════ ✅-[BackgroundTaskManager createBackgroundTask] 13 ✅-[TSHttpService schedulePost] LOCKED: 87B8CF5A-DBF5-47CD-B5AA-86EE5B149EC3

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

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

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

╔═══════════════════════════════════════════════════════════ ║ -[TSLocationManager createMotionTypeChangedHandler]_block_invoke | still/100 | isMoving: 0 ╚═══════════════════════════════════════════════════════════ ℹ️-[TSDBLogger db_delete] maxAge: 604800 🔵-[TSLocationManager onHeartbeat] Heartbeat ⚡️ TO JS {"location":{"coords":{"accuracy":23.699999999999999,"heading_accuracy":-1,"floor":null,"latitude":-19.834561376805464,"speed_accuracy":-1,"heading":-1,"longitude":-44.017138099809117,"speed":-1,"altitude_accuracy":1.3999999999999999,"altitude":873.3999999 ⚡️ [log] - Registro - Heartbeat: {"location":{"coords":{"accuracy":23.7,"heading_accuracy":-1,"floor":null,"latitude":-19.834561376805464,"speed_accuracy":-1,"heading":-1,"longitude":-44.01713809980912,"speed":-1,"altitude_accuracy":1.4,"altitude":873.4,"ellipsoidal_altitude":0},"uuid":"9614440B-BC1A-4727-A607-45FAA6CA77CE","timestamp":"2024-02-27T19:01:49.708Z","activity":{"confidence":100,"type":"still"},"odometer":2995.4,"battery":{"is_charging":true,"level":0.6000000238418579},"age":0,"extras":{},"event":"heartbeat","ismoving":false}} Background Task 13 ("Called by App, from -[TSHttpService flush:]"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(:) for your task in a timely manner to avoid this.

christocracy commented 2 months ago

An SSL error has occurred and a secure connection to the server cannot be made.

Are you not concerned about that?

danillo10 commented 2 months ago

An SSL error has occurred and a secure connection to the server cannot be made.

Are you not concerned about that?

The application is still in the testing phase, I would like to know only why it blocked and is no longer sending locations, and if there is a way to resolve this.

christocracy commented 2 months ago

What makes you think there's a problem?

christocracy commented 2 months ago

If you're relying on preventSuspend to do something every 30s, it's not guaranteed to happen. You should not rely on preventSuspend, it's a brittle hack.

danillo10 commented 2 months ago

I think the issue might be the certificate indeed, thank you!

danillo10 commented 2 months ago

Resolved, I renewed the SSL certificate and enabled it, and it worked fine.