@@ -159,7 +159,7 @@ class G7BluetoothManager: NSObject {
159159
160160 private func managerQueue_stopScanning( ) {
161161 if centralManager. isScanning {
162- log. debug ( " Stopping scan " )
162+ log. default ( " Stopping scan " )
163163 centralManager. stopScan ( )
164164 delegate? . bluetoothManagerScanningStatusDidChange ( self )
165165 }
@@ -170,7 +170,7 @@ class G7BluetoothManager: NSObject {
170170
171171 managerQueue. sync {
172172 if centralManager. isScanning {
173- log. debug ( " Stopping scan on disconnect " )
173+ log. default ( " Stopping scan on disconnect " )
174174 centralManager. stopScan ( )
175175 delegate? . bluetoothManagerScanningStatusDidChange ( self )
176176 }
@@ -180,24 +180,17 @@ class G7BluetoothManager: NSObject {
180180 }
181181 }
182182 }
183-
183+
184184 func centralManager( _ central: CBCentralManager , connectionEventDidOccur event: CBConnectionEvent , for peripheral: CBPeripheral ) {
185-
186185 managerQueue. async {
187- guard self . eventRegistrationActive else {
188- self . centralManager. registerForConnectionEvents ( options: nil )
189- return
190- }
191-
192- self . managerQueue_establishActivePeripheral ( )
193-
194- if !self . eventRegistrationActive {
195- self . centralManager. registerForConnectionEvents ( options: nil )
186+ if self . activePeripheralIdentifier == nil {
187+ self . log. default ( " Discovered peripheral from connectionEventDidOccur %{public}@ " , peripheral. identifier. uuidString)
188+ self . handleDiscoveredPeripheral ( peripheral)
196189 }
197190 }
198191 }
199-
200- private func managerQueue_establishActivePeripheral ( ) {
192+
193+ private func managerQueue_scanForPeripheral ( ) {
201194 dispatchPrecondition ( condition: . onQueue( managerQueue) )
202195
203196 guard centralManager. state == . poweredOn else {
@@ -211,13 +204,14 @@ class G7BluetoothManager: NSObject {
211204 }
212205
213206 if let peripheralID = activePeripheralIdentifier, let peripheral = centralManager. retrievePeripherals ( withIdentifiers: [ peripheralID] ) . first {
214- log. debug ( " Retrieved peripheral %{public}@ " , peripheral. identifier. uuidString)
207+ log. default ( " Retrieved peripheral %{public}@ " , peripheral. identifier. uuidString)
215208 handleDiscoveredPeripheral ( peripheral)
216209 } else {
217210 for peripheral in centralManager. retrieveConnectedPeripherals ( withServices: [
218211 SensorServiceUUID . advertisement. cbUUID,
219212 SensorServiceUUID . cgmService. cbUUID
220213 ] ) {
214+ log. default ( " Found system-connected peripheral: %{public}@ " , peripheral. identifier. uuidString)
221215 handleDiscoveredPeripheral ( peripheral)
222216 }
223217 }
@@ -233,7 +227,13 @@ class G7BluetoothManager: NSObject {
233227 managerQueue_establishActivePeripheral ( )
234228
235229 if activePeripheral == nil {
236- log. debug ( " Scanning for peripherals " )
230+ log. default ( " Scanning for peripherals and listening for connection events " )
231+
232+ centralManager. registerForConnectionEvents ( options: [ CBConnectionEventMatchingOption . serviceUUIDs: [
233+ SensorServiceUUID . advertisement. cbUUID,
234+ SensorServiceUUID . cgmService. cbUUID
235+ ] ] )
236+
237237 centralManager. scanForPeripherals ( withServices: [
238238 SensorServiceUUID . advertisement. cbUUID
239239 ] ,
@@ -295,7 +295,7 @@ class G7BluetoothManager: NSObject {
295295 if let delegate = delegate {
296296 switch delegate. bluetoothManager ( self , shouldConnectPeripheral: peripheral) {
297297 case . makeActive:
298- log. debug ( " Making peripheral active: %{public}@ " , peripheral. identifier. uuidString)
298+ log. default ( " Making peripheral active: %{public}@ " , peripheral. identifier. uuidString)
299299
300300 if let peripheralManager = activePeripheralManager {
301301 peripheralManager. peripheral = peripheral
@@ -311,7 +311,7 @@ class G7BluetoothManager: NSObject {
311311 self . centralManager. connect ( peripheral)
312312
313313 case . connect:
314- log. debug ( " Connecting to peripheral: %{public}@ " , peripheral. identifier. uuidString)
314+ log. default ( " Connecting to peripheral: %{public}@ " , peripheral. identifier. uuidString)
315315 self . centralManager. connect ( peripheral)
316316 let peripheralManager = G7PeripheralManager (
317317 peripheral: peripheral,
@@ -349,7 +349,7 @@ extension G7BluetoothManager: CBCentralManagerDelegate {
349349 fallthrough
350350 @unknown default :
351351 if central. isScanning {
352- log. debug ( " Stopping scan on central not powered on " )
352+ log. default ( " Stopping scan on central not powered on " )
353353 central. stopScan ( )
354354 delegate? . bluetoothManagerScanningStatusDidChange ( self )
355355 }
@@ -370,7 +370,7 @@ extension G7BluetoothManager: CBCentralManagerDelegate {
370370 func centralManager( _ central: CBCentralManager , didDiscover peripheral: CBPeripheral , advertisementData: [ String : Any ] , rssi RSSI: NSNumber ) {
371371 dispatchPrecondition ( condition: . onQueue( managerQueue) )
372372
373- log. info ( " %{public}@: %{public}@, data = %{public}@ " , #function, peripheral, String ( describing: advertisementData) )
373+ log. default ( " %{public}@: %{public}@, data = %{public}@ " , #function, peripheral, String ( describing: advertisementData) )
374374
375375 managerQueue. async {
376376 self . handleDiscoveredPeripheral ( peripheral)
0 commit comments