【问题标题】:How to detect an Apple Watch as a bluetooth peripheral如何将 Apple Watch 检测为蓝牙外围设备
【发布时间】:2018-11-12 01:48:43
【问题描述】:

我正在使用 CoreBluetooth 编译一个提供“心率”服务的连接设备列表,使用 CBCentralManager 方法 retrieveConnectedPeripheralsWithServices

NSArray *services = @[[CBUUID UUIDWithString:BT_DEVICEINFO_SERVICE_UUID],
                      [CBUUID UUIDWithString:BT_HEARTRATE_SERVICE_UUID]];
NSArray *connectedDevices = [_centralMana retrieveConnectedPeripheralsWithServices:services];

此列表包括我作为 CBPeripheral 的 Apple Watch,但一旦连接到connectPeripheral:,此外围设备不会像下面的普通蓝牙心率监测器那样提供任何心率数据:

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
    if ([service.UUID isEqual:[CBUUID UUIDWithString:BT_HEARTRATE_SERVICE_UUID]])  {
        // Apple Watch peripheral never gets here.

        for (CBCharacteristic *aChar in service.characteristics){
            // Request heart rate notifications
            if ([aChar.UUID isEqual:[CBUUID UUIDWithString:BT_HRMEASUREMENT_CHARACTERISTIC_UUID]]) {
                [_currentDevice setNotifyValue:YES forCharacteristic:aChar];
            }
        }
    }
}

我要做的是在连接到 Apple Watch 之前对其进行识别,这样我就可以将其从可用心率设备列表中过滤掉。不幸的是,CBPeripheral 在连接之前似乎只提供了一个字符串“name”和“UUID”。

有谁知道在这里识别 Apple Watch 的方法,或者可能在 retrieveConnectedPeripheralsWithServices 方法使用中将其过滤掉?

【问题讨论】:

    标签: ios core-bluetooth apple-watch cbperipheral


    【解决方案1】:

    原来我只需要意识到服务说明符属于 OR 搜索运算符。 IE。它返回提供任何服务的设备,而不仅仅是提供所有服务的设备。

    Apple Watch 毕竟没有宣传心率服务!

    【讨论】:

      猜你喜欢
      • 2014-07-30
      • 1970-01-01
      • 2015-12-22
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      • 2013-12-13
      相关资源
      最近更新 更多