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

时间:2015-02-09 07:28:12

标签: ios swift xcode6.1

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

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)


    }


}

- 谢谢你

1 个答案:

答案 0 :(得分:0)

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