我想停止,然后在CBCentralManager上重新开始扫描。我的问题是:在调用stopScanning()之后,我应该等待一段时间才能使交易结算吗,还是可以立即进行startScanning()调用?
我不知道较低层和硬件的响应速度。
方法1:
self.stopScanning()
self.startScanning()
方法2:
self.stopScanning()
// wait a few secs for the BLE layer to shutdown to be safe...
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) {
// ...now resume scanning
self.startScanning()
}
在stopScan()之后,在scanForPeripherals(withServices:options :)之前的一小段延迟,或者监视isScanning属性都可能与您的问题有关。
我要考虑的另一个问题是BLE是为实现最低功耗而设计的,而扫描是一个非常耗电的过程,应尽可能少地进行。 Apple在Best Practices for Interacting with a Remote Peripheral Device下的第一项关于如何避免扫描或最小化扫描的时间/功耗。因此,在应用程序设计中也必须考虑到这一点。