iOS Question Low power mode for GPS tracking with FusedLocation and MotionActivity — is this the right approach?

nicieri

Active Member
Licensed User
Longtime User
Using FusedLocation in B4i, I detect when the device is stationary or the battery is low with MotionActivity, and then apply this low power mode:


B4X:
Public Sub ApplyLowPowerTracking(lm As LocationManager)
If lm = Null Then Return
currentSignificantMode = True
Dim no As NativeObject = lm
no = no.GetField("manager")
If no.IsInitialized = False Then Return
If App.OSVersion >= 9 Then no.RunMethod("setAllowsBackgroundLocationUpdates:", Array(True))
no.SetField("desiredAccuracy", 1000)
no.SetField("distanceFilter", 1000)
no.SetField("pausesLocationUpdatesAutomatically", True)
no.SetField("activityType", 1) ' CLActivityTypeFitness
EnableSCM(lm) ' startMonitoringSignificantLocationChanges
End Sub


When MotionActivity detects movement again, I disable low power mode and set the normal or intensive tracking mode:

B4X:
Public Sub SetTrackingMode(Intensive As Boolean)
currentTrackingIntensive = Intensive
If fl.IsInitialized = False Or fl.FLP = Null Then Return
Dim no As NativeObject = fl.FLP
no = no.GetField("manager")
Try
no.SetField("desiredAccuracy", IIf(Intensive, 50, 100))
no.SetField("distanceFilter", IIf(Intensive, 1, 10))
no.SetField("pausesLocationUpdatesAutomatically", False)
Catch
Log("Error configuring TrackingMode: " & LastException)
Return
End Try
If IsValidLocationManager(fl.FLP) = False Then
    gpsWatchdog_Tick
End If
End Sub
 

nicieri

Active Member
Licensed User
Longtime User
Hi! Does anyone have any idea why iOS might stop updating positions without throwing any errors?
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
Hi, yes, I'm using NHFusedLocation and the MotionActivity class. I've also been monitoring for crashes using Crashlytics and a custom ReleaseLogger, but neither of them report any errors — it's as if iOS simply stops delivering location updates to my app.


The app is designed to run in the background as a full tracking system. It detects when the user is stationary to reduce power consumption, then switches back to active mode when movement is detected, reporting locations continuously.


The system works very well overall — the logic and functionality are nearly perfect. The main concern has been battery usage, which is why I'm trying to optimize the stationary mode to lower consumption. However, that hasn't significantly improved battery performance.


The bigger issue, though, is what I mentioned earlier: iOS suspends the app without actually terminating it. There’s no crash, no error — nothing is reported by Firebase Crashlytics, by my own internal error-reporting logic, or by the ReleaseLogger. It’s completely silent.


I can keep the app running in Debug mode for many hours, even days, without issues. The problem only occurs in Release mode, and only after several hours of operation.


I’d really appreciate any guidance or suggestions you might have. Thank you!
 
Upvote 0

nicieri

Active Member
Licensed User
Longtime User
Does anyone know how to save battery life on iOS? If you use the suggested modes, iOS may stop updating its positions.
 
Upvote 0
Top