scanForPeripherals(withServices:options:)
Scans for peripherals that are advertising services.
Declaration
func scanForPeripherals(withServices serviceUUIDs: [CBUUID]?, options: [String : Any]? = nil)Parameters
- serviceUUIDs:
An array of Cbuuid objects that the app is interested in. Each Cbuuid object represents the UUID of a service that a peripheral advertises.
- options:
A dictionary of options for customizing the scan. For available options, see Peripheral Scanning Options.
Discussion
You can provide an array of CBUUID objects — representing service UUIDs — in the serviceUUIDs parameter. When you do, the central manager returns only peripherals that advertise the services you specify. If the serviceUUIDs parameter is nil, this method returns all discovered peripherals, regardless of their supported services.
If the central manager is actively scanning with one set of parameters and it receives another set to scan, the new parameters override the previous set. When the central manager discovers a peripheral, it calls the centralManager(_:didDiscover:advertisementData:rssi:) method of its delegate object.
Your app can scan for Bluetooth devices in the background by specifying the bluetooth-central background mode. To do this, your app must explicitly scan for one or more services by specifying them in the serviceUUIDs parameter. The CBCentralManager scan option has no effect while scanning in the background.