我正在使用 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/