swift中的哪种方法可以用于查找BLE设备之间的距离



我已经实现了两种方法来检查蓝牙功能的可用性和找到我们周围可发现的设备。现在我想找到我们周围外围设备的距离。对于这些功能,可以使用哪种方法和要实现的代码。期望使用示例代码的解决方案

func centralManagerDidUpdateState(central: CBCentralManager!) {
    println("(__LINE__) (__FUNCTION__)")
     println("checking state")
    if central.state != .PoweredOn {
        // In a real app, you'd deal with all the states correctly
                    return
    }
    central.scanForPeripheralsWithServices(nil,options:nil)

}
func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!)
{
    var localname: NSString = advertisementData[CBAdvertisementDataLocalNameKey]! as NSString
    println("Discovered: (peripheral.name)")
    peri = ["(peripheral.name)"]

    if localname != " "
    {
        //centralManager!.stopScan()
        //self.peripheral = peripheral
        peripheral.delegate = self
        centralManager!.connectPeripheral(peripheral, options: nil)

    }

}

-感谢

您可以通过读取RSSI方法获得近似距离。它不会以任何厘米或公制值返回距离。您应该将其转换为可理解的格式

最新更新