From df3eb0eca013383c4936fad9d0c1f6276bfccae0 Mon Sep 17 00:00:00 2001 From: Michiel Visser Date: Sat, 13 Jan 2018 13:25:40 +0100 Subject: [PATCH] Restart scanning every 10 seconds, so connected devices are detected --- AnnePro/BluetoothController.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/AnnePro/BluetoothController.swift b/AnnePro/BluetoothController.swift index 460ded5..c962ba1 100644 --- a/AnnePro/BluetoothController.swift +++ b/AnnePro/BluetoothController.swift @@ -101,7 +101,12 @@ class BluetoothController: NSObject, CBCentralManagerDelegate, CBPeripheralDeleg self.centralManager.connect(peripheral, options: nil) } else { print("No paired peripherals found, scanning...") - central.scanForPeripherals(withServices: nil, options: nil) + central.scanForPeripherals(withServices: [ANNE_PRO_SERVICE_UUID], options: nil) + DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { + print("reload scan") + central.stopScan() + self.centralManagerDidUpdateState(central) + } } } else { print("Bluetooth not available.") @@ -180,8 +185,7 @@ class BluetoothController: NSObject, CBCentralManagerDelegate, CBPeripheralDeleg if self.peripheral == peripheral && self.peripheral.state != .connected { self.peripheral = nil self.writeCharacteristic = nil - delegate?.updateStatus(status: .SCANNING) - central.scanForPeripherals(withServices: nil, options: nil) + self.centralManagerDidUpdateState(central) } }