【发布时间】: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