2
votes

I am trying to connect to a heart-rate monitor using the CoreBluetooth API.

According to the bluetooth spec the heart rate monitor service is 0x180D. To know what services a bluetooth device has you can connect to it and than request the available services. If one of the device services is 0x180D you got a heart rate monitor. Unfortunately that means connecting to all nearby bluetooth devices to filter the heartrate monitor.

Fortunately iOS has the following method -scanForPeripheralsWithServices: which scans for bluetooth devices advertising a specific service. The problem I am having is that some heart rate monitors advertise their service but some don't.

How do other apps connect to heart rate monitors? Do they connect to every bluetooth device nearby to discover if it is a heart rate monitor?

1
At the moment I am doing the later. Which seems more tedious to connect to every nearby device but it also works faster and more reliable than waiting till devices advertise their service.automaticoo

1 Answers

1
votes

Core Bluetooth can only filter based on the data it knows. If a device advertises the 180D service, then your app will discover it while filtering. If the device doesn't advertise 180D, then CB (or anything else) has no additional info that would make it eligible for being selected.

Therefore, the only way to detect all devices is to scan without filtering for specific services. This is the simplest and most efficient way.