【问题标题】:Corebluetooth - Scanning for specific CBUUID not workingCorebluetooth - 扫描特定 CBUUID 不起作用
【发布时间】:2018-07-10 22:32:07
【问题描述】:

我可以成功扫描所有可连接的蓝牙设备:

_manager?.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey:true])

但是当我尝试从特定 CBUUID 进行扫描时,我的应用没有发现蓝牙设备。

 _manager?.scanForPeripherals(withServices: [CBUUID(string: "FFF1")], options: [CBCentralManagerScanOptionAllowDuplicatesKey:true])

我使用具有相同 FFF1 服务 UUID 的 LightBlue ios 应用程序创建了一个虚拟设备,并且 2. 代码按预期工作。但它没有发现具有相同服务 UUID FFF1 的真正蓝牙设备。

注意:除了搜索特定 CBUUID 之外,所有功能、连接、发现服务、发现特征、读写工作正常。

【问题讨论】:

  • 设备是否真的在宣传该服务?提供的服务集可以大于广告的服务集
  • @Paulw11 上的 +1 这不是因为设备有服务,它才会宣传它。当你做...(withServices: nil...时,检查didDiscoverPeripheral是什么广告(打印),如果没有出现“FFF1”,那就是它失败的原因。
  • 你是对的,设备没有宣传该服务。

标签: swift core-bluetooth


【解决方案1】:

我已经在 iOS13.5 中检查了你的代码。

你会得到解决方案的。谢谢

//precomputed 128 bit value from the Notification API's 16 bit value: 0xFFF1
//static let serviceUUID = CBUUID(string: "0000FFF1-0000-1000-8000-00805F9B34FB")

 _manager?.scanForPeripherals(withServices: [serviceUUID], options: [CBCentralManagerScanOptionAllowDuplicatesKey:true])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-02
    • 2016-05-06
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 2014-12-25
    • 2019-05-03
    • 1970-01-01
    相关资源
    最近更新 更多