Skip to content

Commit

Permalink
Restart scanning every 10 seconds, so connected devices are detected
Browse files Browse the repository at this point in the history
  • Loading branch information
msvisser committed Jan 13, 2018
1 parent 05ffe4b commit df3eb0e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions AnnePro/BluetoothController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit df3eb0e

Please sign in to comment.