【发布时间】:2018-11-15 23:13:42
【问题描述】:
我正在编写一个自定义蓝牙连接器,我希望搜索查询与 mac os 中的标准蓝牙应用程序完全相同。我怎样才能做到这一点?我正在使用 CoreBluetooth 和 IOBluetooth 框架来实现这一点,但得到了包括电视等在内的各种设备。
从docs我了解到我想在其中提供特定的服务
.scanForPeripherals(withServices: [CBUUID], options: nil)
但是什么服务呢?我还找到了默认的 Xcode 蓝牙连接器,但它不包含源代码。
现在我的代码是:
let cbuuids = [CBUUID(string: "0x180A"), CBUUID(string: "0x1801"), CBUUID(string: "0x1800"), CBUUID(string: "0x1812")]
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .poweredOn:
print("powered on")
central.scanForPeripherals(withServices: cbuuids, options: nil)
case .unknown:
print("state unknown")
case .resetting:
print("resetting")
case .unsupported:
print("unsupported")
case .unauthorized:
print("unauthorized")
case .poweredOff:
print("powered off")
}
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
print(peripheral.name)
devices.append(peripheral)
devices = devices.unique
tableView.reloadData()
scrubber.reloadData()
}
我正在将搜索查询加载到触摸栏的洗涤器,但这不是重点。
有没有办法匹配标准应用程序中的原始设备列表?任何建议表示赞赏。
【问题讨论】:
标签: swift macos bluetooth core-bluetooth