Open hgroschaus opened 1 year ago
\newpage
OS | OS version | Langage |
---|---|---|
IOS | - | Swift |
ID | Title | Category | Sub-category |
---|---|---|---|
- | Stop scanning when you found your device | - | - |
Severity | Remediation Cost |
---|---|
Minor | Minor |
When you call the scanForPeripheralsWithServices:options method of the CBCentralManager class to discover remote peripherals that are advertising services, the device uses its radio to listen for advertising devices until explicitly told to stop.
Unless you need to discover more devices, stop scanning for other devices once you have found one you want to connect to. Use the stopScan method of the CBCentralManager class to stop scanning for other devices.
When you call the scanForPeripheralsWithServices:options
method of the CBCentralManager
class to discover remote peripherals that are advertising services, the device uses its radio to listen for advertising devices until explicitly told to stop.
Unless you need to discover more devices, stop scanning for other devices once you have found one you want to connect to. Use the stopScan
method of the CBCentralManager
class to stop scanning for other devices.
func beginScanningForDevice() {
// Create a Core Bluetooth Central Manager object
self.myCentralManager = CBCentralManager(delegate: self, queue: nil, options: nil)
// Scan for peripherals
self.myCentralManager.scanForPeripheralsWithServices(nil, options: nil)
}
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral:
CBPeripheral, advertisementData: [NSObject: AnyObject]!, RSSI: NSNumber!) {
// Connect to the newly discovered device
// Stop scanning for devices
self.myCentralManager.stopScan()
}
<p>When you call the <code>scanForPeripheralsWithServices:options</code> method of the <code>CBCentralManager</code>class to discover remote peripherals that are advertising services, the device uses its radio to listen for advertising devices until explicitly told to stop.</p>
<p>Unless you need to discover more devices, stop scanning for other devices once you have found one you want to connect to. Use the <code>stopScan</code> method of the <code>CBCentralManager</code> class to stop scanning for other devices.</p>
<h2>Compliant Solution</h2>
<pre>
func beginScanningForDevice() {
// Create a Core Bluetooth Central Manager object
self.myCentralManager = CBCentralManager(delegate: self, queue: nil, options: nil)
// Scan for peripherals
self.myCentralManager.scanForPeripheralsWithServices(nil, options: nil)
}
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral:
CBPeripheral, advertisementData: [NSObject: AnyObject]!, RSSI: NSNumber!) {
// Connect to the newly discovered device
// Stop scanning for devices
self.myCentralManager.stopScan()
}
</pre>
When you call the
scanForPeripheralsWithServices:options
method of theCBCentralManager
class to discover remote peripherals that are advertising services, the device uses its radio to listen for advertising devices until explicitly told to stop.Unless you need to discover more devices, stop scanning for other devices once you have found one you want to connect to. Use the
stopScan
method of theCBCentralManager
class to stop scanning for other devices