André Fratelli
André Fratelli

Reputation: 6068

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?

Upvotes: 8

Views: 1584

Answers (1)

Paulw11
Paulw11

Reputation: 115012

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.

Upvotes: 17

Related Questions