【发布时间】:2018-04-29 01:37:34
【问题描述】:
在 MacOS 上扫描 BluetoothLE 制造商广告时,发现回调的频率远低于 iOS。对于 10 Hz 的发射器广告,iOS 每秒会收到近 10 个发现回调。在 MacOS 上,通常每秒会看到 1-3 个回调,但有时回调之间可能会有很多秒——有几次我测量的检测间隔超过 90 秒!下面是我所做的图表,显示了在大约两个小时的测试运行中发现之间的秒数。
与 iOS 相比,为什么 MacOS 上的发现时间如此难以预测?有没有办法让回调更可靠?
我在 MacBook Pro(Retina,15 英寸,2014 年中)上的 macOS Sierra 10.12.6 上记录了这些数据,但我听到同事抱怨新款 MacBook 存在类似的不可靠性。
centralManager = CBCentralManager(delegate: self,
queue: DispatchQueue.global(qos: .default))
centralManager.scanForPeripherals(withServices: nil,
options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
...
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
let secsSinceDetection = Date().timeIntervalSince(self.lastDetectionTime)
lastDetectionTime = Date()
NSLog("LDT: \(secsSinceDetection))")
}
【问题讨论】:
标签: macos core-bluetooth