diff --git a/SulTee/SulTee/BLEManager.swift b/SulTee/SulTee/BLEManager.swift index 5dd3906..53c3ef3 100644 --- a/SulTee/SulTee/BLEManager.swift +++ b/SulTee/SulTee/BLEManager.swift @@ -42,6 +42,10 @@ final class BLEManager: NSObject, ObservableObject { override init() { super.init() + // autoReconnect=true before creating the central so that + // centralManagerDidUpdateState(.poweredOn) immediately starts scanning + // without any user action. The user can still tap Disconnect to stop. + autoReconnect = true central = CBCentralManager(delegate: self, queue: DispatchQueue(label: "ble.queue", qos: .utility)) } @@ -95,12 +99,13 @@ final class BLEManager: NSObject, ObservableObject { // We filter by device name prefix in didDiscover instead. central.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey: false]) - // Auto-stop after 15 s if nothing found + // Stop after 15 s if nothing found, then retry after 5 s (TAG may be booting) scanTimer?.invalidate() scanTimer = Timer.scheduledTimer(withTimeInterval: 15, repeats: false) { [weak self] _ in guard let self else { return } self.stopScan() DispatchQueue.main.async { self.connectionState = .idle } + self.reconnectAfterDelay() } }