【问题标题】:Can't discover peripheral using service UUID无法使用服务 UUID 发现外围设备
【发布时间】:2018-10-11 01:51:05
【问题描述】:

我正在尝试检测我拥有的自行车功率计。我使用应用程序 LightBlue 来确定功率计的服务 UUID,即 E9410100-B434-446B-B5CC-36592FC4C724。

但是当我使用 CBCentralManager 发现具有此 UUID 的设备时,什么都没有发现:

manager?.scanForPeripherals(withServices: [CBUUID(string: "E9410100-B434-446B-B5CC-36592FC4C724")], options: nil)

我应该使用这个 UUID 的缩短版本吗?

【问题讨论】:

  • 您能否也展示您的 LightBlue 屏幕截图和您实现的 CBCentralManagerDelegate?它可以扫描其他设备吗?如果您使用withServices: nil,它可以扫描您的骑行功率计吗?

标签: ios swift bluetooth-lowenergy


【解决方案1】:

您无需搜索特定设备的标识符(无论如何,这对于每个 iOS 设备都是唯一的)。相反,您搜索的是宣传您感兴趣的服务的外围设备。

cycling power的情况下,这是0x1818

你想要:

manager?.scanForPeripherals(withServices: [CBUUID(string: "1818")], options: nil)

【讨论】:

  • 那你需要展示更多代码;你确定你的委托是正确创建的吗?你的manager 不是nil。如果为 services 数组指定 nil 会发生什么?
猜你喜欢
  • 1970-01-01
  • 2014-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多