Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scanForPeripheralsWithServices:options: and CBCentralManagerScanOptionSolicitedServiceUUIDsKey

I have a question that I got by reading Apple's documentation. When it comes to CBCentralManagerScanOptionSolicitedServiceUUIDsKey Apple's documentation states:

An array (an instance of NSArray) of service UUIDs (represented by CBUUID objects) that you want to scan for.

Specifying this scan option causes the central manager to also scan for peripherals soliciting any of the services contained in the array.

On regard of scanForPeripheralsWithServices:options:'s first argument, however:

An array of CBUUID objects that the app is interested in. In this case, each CBUUID object represents the UUID of a service that a peripheral is advertising.

So what's the difference? Why use one or the other?

like image 960
André Fratelli Avatar asked Jan 09 '23 02:01

André Fratelli


1 Answers

Typically the Bluetooth peripheral advertises services and the central scans for those services. This is the case covered by the first parameter.

In some cases, however, the behaviour is reversed - the central offers the service and the peripheral looks for it. This is called service solicitation. When you supply an array of service identifiers using CBCentralManagerScanOptionSolicitedServiceUUIDsKey you are providing the list of services that the central will 'advertise' to peripherals.

It is still the responsibility of the central to initiate the connection, so once a peripheral is identified that is soliciting for one of those services, you will receive a call to the didDiscoverPeripheral method as per usual.

like image 176
Paulw11 Avatar answered Jan 14 '23 17:01

Paulw11