Skip to content

Commit 205054e

Browse files
committed
Use scanAfterDelay for connect/disconnect issue
1 parent d86ac8e commit 205054e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

G7SensorKit/G7CGMManager/G7BluetoothManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class G7BluetoothManager: NSObject {
259259
The sleep gives the transmitter time to shut down, but keeps the app running.
260260

261261
*/
262-
fileprivate func scanAfterDelay() {
262+
func scanAfterDelay() {
263263
DispatchQueue.global(qos: .utility).async {
264264
Thread.sleep(forTimeInterval: 5)
265265

G7SensorKit/G7CGMManager/G7CGMManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ public class G7CGMManager: CGMManager {
237237
return nil
238238
}
239239

240-
public func scanForNewSensor() {
240+
public func scanForNewSensor(scanAfterDelay: Bool = false) {
241241
logDeviceCommunication("Forgetting existing sensor and starting scan for new sensor.", type: .connection)
242242

243243
mutateState { state in
244244
state.sensorID = nil
245245
state.activatedAt = nil
246246
}
247-
sensor.scanForNewSensor()
247+
sensor.scanForNewSensor(scanAfterDelay: scanAfterDelay)
248248
}
249249

250250
private var device: HKDevice? {
@@ -319,7 +319,7 @@ extension G7CGMManager: G7SensorDelegate {
319319
public func sensorDisconnected(_ sensor: G7Sensor, suspectedEndOfSession: Bool) {
320320
logDeviceCommunication("Sensor disconnected: suspectedEndOfSession=\(suspectedEndOfSession)", type: .connection)
321321
if suspectedEndOfSession {
322-
scanForNewSensor()
322+
scanForNewSensor(scanAfterDelay: true)
323323
}
324324
}
325325

G7SensorKit/G7CGMManager/G7Sensor.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ public final class G7Sensor: G7BluetoothManagerDelegate {
9999
bluetoothManager.delegate = self
100100
}
101101

102-
public func scanForNewSensor() {
102+
public func scanForNewSensor(scanAfterDelay: Bool = false) {
103103
self.sensorID = nil
104104
bluetoothManager.disconnect()
105105
bluetoothManager.forgetPeripheral()
106-
bluetoothManager.scanForPeripheral()
106+
if scanAfterDelay {
107+
bluetoothManager.scanAfterDelay()
108+
} else {
109+
bluetoothManager.scanForPeripheral()
110+
}
107111
}
108112

109113
public func resumeScanning() {

0 commit comments

Comments
 (0)