Fix iOS background Bluetooth connectivity issues (#378)

- Implement Core Bluetooth state restoration with restoration identifiers
- Add background task management to protect critical BLE operations
- Fix aggressive battery optimization that killed background connectivity
- Disable scan duty cycling in background (was causing 89-97% downtime)
- Add missing didEnterBackground/willEnterForeground notifications
- Fix advertising cutoff in low battery conditions (now only <10%)
- Add background-processing entitlement to Info.plist
- Optimize scan parameters for background vs foreground modes

These changes address the issue where devices lose mesh connectivity when
the app is backgrounded, ensuring continuous Bluetooth operation within
iOS background execution limits.

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2025-08-01 12:18:14 +02:00
committed by GitHub
co-authored by jack
parent b004bfa4aa
commit aa1ecf40fc
3 changed files with 302 additions and 12 deletions
+6 -4
View File
@@ -184,13 +184,15 @@ class BatteryOptimizer {
// When charging, use performance mode unless battery is critical
currentPowerMode = batteryLevel < 0.1 ? .balanced : .performance
} else if isInBackground {
// In background, always use power saving
if batteryLevel < 0.2 {
// In background, be less aggressive with power management
// Don't force ultra-low power mode until battery is below 10%
// Use balanced mode in background above 30% battery
if batteryLevel < 0.1 {
currentPowerMode = .ultraLowPower
} else if batteryLevel < 0.5 {
} else if batteryLevel < 0.3 {
currentPowerMode = .powerSaver
} else {
currentPowerMode = .balanced
currentPowerMode = .balanced // Use balanced mode above 30% in background
}
} else {
// Foreground, not charging