2
votes

I'm trying to find a good way for my iOS app to scan for three different types of Bluetooth LE peripherals, each represented by a unique service/UUID. The CBCentralManager scanForPeripheralsWithServices:options methods takes an array of service UUIDs and the documentation states that "the central manager returns only peripherals that advertise the services you specify" when this is provided. However I found that what this actually means is that if you specify 3 service UUIDs, you will get only the peripherals that advertise all three of those services. i.e. it's an AND not an OR: it will not return all of the peripherals that advertise ANY of those services in the array.

The only other option that I see is to pass a 'nil' for the array of service UUIDs, and per the documentation "all discovered peripherals are returned regardless of their supported services (not recommended)". I could then filter for any of the three service UUIDs I am looking for. But Apple seems to be dissuading me from doing this by telling me it is not recommended. Anyone know why?

1

1 Answers

3
votes

Apple doesn't recommend the use of nil because it isn't as efficient and can impact battery life.

The solution is simply to create three CBCentralManager instances and have each instance scan for a different service. You can even use the same delegate instance because the CBCentralManager instance is passed to the delegate methods.