我用这个功能来扫描我周围的BLE,但是我收到的信号太多了。我只想处理来自信标的信号。
func centralManagerDidUpdateState(_ central: CBCentralManager) {
centralManager.scanForPeripherals(withServices: nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey : NSNumber(value: true)])
}我用过LightBlue发现我的信标有5个服务:180 A,FFA0,FFB0,FFF0和180 F。
然后我尝试了这段代码,但是没有在这个服务中找到外设。
let serviceUUIDs = [CBUUID(string: "FFA0")]
func centralManagerDidUpdateState(_ central: CBCentralManager) {
centralManager.scanForPeripherals(withServices: serviceUUIDs, options: [CBCentralManagerScanOptionAllowDuplicatesKey : NSNumber(value: true)])
}而didDiscover方法从未调用过
func centralManager(_ central: CBCentralManager,
didDiscover peripheral: CBPeripheral,
advertisementData: [String : Any],
rssi: NSNumber)
{
if peripheral.name == "MY_BEACON_NAME" {
print("peripheral: \(peripheral)")
print("rssi = \(rssi)")
}
}我做错什么了?
我不能在这个项目中使用CoreLocation,只有CoreBluetooth。
发布于 2018-03-06 17:26:56
根据您的硬件信标是什么类型的信标格式广告,可能无法检测到与CoreBluetooth。CoreBluetooth可以检测Eddystone格式和AltBeacon格式,但不能检测iBeacon格式。
有几点需要理解:
centralManager.scanForPeripherals(withServices: serviceUUIDs ...时过滤的内容。虽然Eddystone广告确实包括服务UUID,但iBeacon和AltBeacon并不是因为它们是另一种叫做制造商广告的BLE广告。只有GATT广告有服务UUID。底线:没有一种简单的方法可以使用CoreBluetooth来过滤你想要的信标。您最好的选择是在CoreBluetooth上编写自己的过滤软件,而忽略您不关心的数据包。
https://stackoverflow.com/questions/49134666
复制相似问题