func startScan() {
guard centralManager.state == .poweredOn else { return }
let uuid = CBUUID(string: "FFE0")
centralManager.scanForPeripherals(withServices: [uuid], option: nil)
let peripherals = centralManager.retrieveConnetedPeripherals(withServices: [uuid])
for peripheral in peripherals {
delegate.serialDidDiscoverPeripheral(peripheral, RSSI: nil)
}
}
func stopScan() {
centralManager.stopScan()
}
func connectToPeripheral(_peripheral: CBPeripheral) {
pendingPeripheral = peripheral
centralManager.connect(peripheral, options: nil)
}
func disconnect() {
if let p = connectedPeripheral {
centralManager.cancelPeripheralConnection(p)
} else if let p = pendingPeripheral {
centralManager.cancelPeripheralConnection(p)
}
}
±¸ºÐ | ³»¿ë |
---|---|
À ±Û | About Bluetooth data process |
¾Æ·§±Û |