I'm using CoreBluetooth to compile a list of connected devices offering the "heart rate" service with the CBCentralManager
method retrieveConnectedPeripheralsWithServices
.
NSArray *services = @[[CBUUID UUIDWithString:BT_DEVICEINFO_SERVICE_UUID],
[CBUUID UUIDWithString:BT_HEARTRATE_SERVICE_UUID]];
NSArray *connectedDevices = [_centralMana retrieveConnectedPeripheralsWithServices:services];
This list includes my Apple Watch as a CBPeripheral, yet once connected with connectPeripheral:
, this peripheral does not offer any heart rate data as do normal Bluetooth heart rate monitors below:
- (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];
}
}
}
}
What I'm trying to do is identify the Apple Watch before connecting to it so I can filter it out of a list of available heart rate devices. Unfortunately, the CBPeripheral only seems to offer a string "name" and "UUID" before connecting.
Does anyone know a way to identify an Apple Watch here, or perhaps filter it out in the retrieveConnectedPeripheralsWithServices
method usage?
Turns out I just needed to realize that the services specifier falls into an OR search operator. I.e. It returns devices that offer ANY of the services, not just devices that offer all of them.
Apple Watch did not advertise the heart rate service after all!