ios - 如何将 Apple Watch 检测为蓝牙外设

标签 ios core-bluetooth apple-watch cbperipheral

我正在使用 CoreBluetooth 通过 CBCentralManager 方法 retrieveConnectedPeripheralsWithServices 编译提供“心率”服务的已连接设备列表。

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

此列表包括我的 Apple Watch 作为 CBPeripheral,但一旦与 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 方法用法中将其过滤掉吗?

最佳答案

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

Apple Watch 终究没有宣传心率服务!

关于ios - 如何将 Apple Watch 检测为蓝牙外设,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50651552/

相关文章:

ios - Apple Watch、WatchKit 和 NSUserDefaults

ios - 如何使用 GLKit 的 GLKMatrixStack 库生成模型 View 矩阵?

ios - 如何在 Xcode 和 Swift 中快速查看变量类型?

ios - Xcode 13/iOS15 的启动时间比预期的要长,它显示了与 LLDB 相关的消息

ios - 在 Objective-C 中使用蓝牙

ios - Apple Watch 应用和 Watch 扩展的配置文件

ios - 如何获得 UITableViewCell 移动开始和结束的通知?

ios7 - 当应用程序进入后台时,startAdvertisingPeer 是否工作?

ios - 如果先连接其他应用程序,CoreBluetooth 不会发现心率监视器

mapkit - 如何在watchOS WKInterfaceMap上绘制折线?