func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
Logger.debug("收 ",characteristic.uuid,characteristic.value?.joined() ?? "")
guard let data = characteristic.value else { return }
+ if data.count < 4 {
+ return
+ }
if let sender = BleSender.answer(data) {
sender.completion?(.response.code(.success).value(data))
self?.list = devices
self?.tableView.reloadData()
}
+ BleManager.shared.didConnectDeviceCallback = { [weak self] de in
+ self?.navigationController?.popViewController(animated: true)
+ }
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let data = list[indexPath.row]
didSelectedCallback?(data)
- self.navigationController?.popViewController(animated: true)
BleManager.shared.stopScanDevice()
}
}
peripheral.delegate = self
peripheral.discoverServices(nil);
DCBleManager.shared.centralManager(central, didConnect: peripheral)
+ self.didConnectDeviceCallback?(peripheral)
App.shared.window?.makeToast("蓝牙已连接")
}
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {