如何将 Apple Watch 检测为蓝牙外围设备
How to detect an Apple Watch as a bluetooth peripheral
我正在使用 CoreBluetooth 编译一个连接设备列表,这些设备使用 CBCentralManager
方法 retrieveConnectedPeripheralsWithServices
提供 "heart rate" 服务。
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。它 returns 提供任何服务的设备,而不仅仅是提供所有服务的设备。
Apple Watch毕竟没有宣传心率服务!
我正在使用 CoreBluetooth 编译一个连接设备列表,这些设备使用 CBCentralManager
方法 retrieveConnectedPeripheralsWithServices
提供 "heart rate" 服务。
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。它 returns 提供任何服务的设备,而不仅仅是提供所有服务的设备。
Apple Watch毕竟没有宣传心率服务!