@@ -156,7 +156,7 @@ class G7BluetoothManager: NSObject {
156156
157157 private func managerQueue_stopScanning( ) {
158158 if centralManager. isScanning {
159- log. debug ( " Stopping scan " )
159+ log. default ( " Stopping scan " )
160160 centralManager. stopScan ( )
161161 delegate? . bluetoothManagerScanningStatusDidChange ( self )
162162 }
@@ -167,7 +167,7 @@ class G7BluetoothManager: NSObject {
167167
168168 managerQueue. sync {
169169 if centralManager. isScanning {
170- log. debug ( " Stopping scan on disconnect " )
170+ log. default ( " Stopping scan on disconnect " )
171171 centralManager. stopScan ( )
172172 delegate? . bluetoothManagerScanningStatusDidChange ( self )
173173 }
@@ -178,6 +178,15 @@ class G7BluetoothManager: NSObject {
178178 }
179179 }
180180
181+ func centralManager( _ central: CBCentralManager , connectionEventDidOccur event: CBConnectionEvent , for peripheral: CBPeripheral ) {
182+ managerQueue. async {
183+ if self . activePeripheralIdentifier == nil {
184+ self . log. default ( " Discovered peripheral from connectionEventDidOccur %{public}@ " , peripheral. identifier. uuidString)
185+ self . handleDiscoveredPeripheral ( peripheral)
186+ }
187+ }
188+ }
189+
181190 private func managerQueue_scanForPeripheral( ) {
182191 dispatchPrecondition ( condition: . onQueue( managerQueue) )
183192
@@ -191,19 +200,26 @@ class G7BluetoothManager: NSObject {
191200 }
192201
193202 if let peripheralID = activePeripheralIdentifier, let peripheral = centralManager. retrievePeripherals ( withIdentifiers: [ peripheralID] ) . first {
194- log. debug ( " Retrieved peripheral %{public}@ " , peripheral. identifier. uuidString)
203+ log. default ( " Retrieved peripheral %{public}@ " , peripheral. identifier. uuidString)
195204 handleDiscoveredPeripheral ( peripheral)
196205 } else {
197206 for peripheral in centralManager. retrieveConnectedPeripherals ( withServices: [
198207 SensorServiceUUID . advertisement. cbUUID,
199208 SensorServiceUUID . cgmService. cbUUID
200209 ] ) {
210+ log. default ( " Found system-connected peripheral: %{public}@ " , peripheral. identifier. uuidString)
201211 handleDiscoveredPeripheral ( peripheral)
202212 }
203213 }
204214
205215 if activePeripheral == nil {
206- log. debug ( " Scanning for peripherals " )
216+ log. default ( " Scanning for peripherals and listening for connection events " )
217+
218+ centralManager. registerForConnectionEvents ( options: [ CBConnectionEventMatchingOption . serviceUUIDs: [
219+ SensorServiceUUID . advertisement. cbUUID,
220+ SensorServiceUUID . cgmService. cbUUID
221+ ] ] )
222+
207223 centralManager. scanForPeripherals ( withServices: [
208224 SensorServiceUUID . advertisement. cbUUID
209225 ] ,
@@ -257,7 +273,7 @@ class G7BluetoothManager: NSObject {
257273 if let delegate = delegate {
258274 switch delegate. bluetoothManager ( self , shouldConnectPeripheral: peripheral) {
259275 case . makeActive:
260- log. debug ( " Making peripheral active: %{public}@ " , peripheral. identifier. uuidString)
276+ log. default ( " Making peripheral active: %{public}@ " , peripheral. identifier. uuidString)
261277
262278 if let peripheralManager = activePeripheralManager {
263279 peripheralManager. peripheral = peripheral
@@ -273,7 +289,7 @@ class G7BluetoothManager: NSObject {
273289 self . centralManager. connect ( peripheral)
274290
275291 case . connect:
276- log. debug ( " Connecting to peripheral: %{public}@ " , peripheral. identifier. uuidString)
292+ log. default ( " Connecting to peripheral: %{public}@ " , peripheral. identifier. uuidString)
277293 self . centralManager. connect ( peripheral)
278294 let peripheralManager = G7PeripheralManager (
279295 peripheral: peripheral,
@@ -311,7 +327,7 @@ extension G7BluetoothManager: CBCentralManagerDelegate {
311327 fallthrough
312328 @unknown default :
313329 if central. isScanning {
314- log. debug ( " Stopping scan on central not powered on " )
330+ log. default ( " Stopping scan on central not powered on " )
315331 central. stopScan ( )
316332 delegate? . bluetoothManagerScanningStatusDidChange ( self )
317333 }
@@ -332,7 +348,7 @@ extension G7BluetoothManager: CBCentralManagerDelegate {
332348 func centralManager( _ central: CBCentralManager , didDiscover peripheral: CBPeripheral , advertisementData: [ String : Any ] , rssi RSSI: NSNumber ) {
333349 dispatchPrecondition ( condition: . onQueue( managerQueue) )
334350
335- log. info ( " %{public}@: %{public}@, data = %{public}@ " , #function, peripheral, String ( describing: advertisementData) )
351+ log. default ( " %{public}@: %{public}@, data = %{public}@ " , #function, peripheral, String ( describing: advertisementData) )
336352
337353 managerQueue. async {
338354 self . handleDiscoveredPeripheral ( peripheral)
0 commit comments