swift中的哪种方法可以用来计算BLE设备之间的距离?
Which method in swift can be used to find the distance between the BLE devices?
我已经实现了两种方法来检查蓝牙功能的可用性和找到我们周围可发现的设备。现在我想找到我们周围外围设备的距离。对于这些功能可以使用哪些方法以及要实现哪些代码。期待带有示例代码的解决方案
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方法得到一个大概的距离。它不会 return 任何厘米或公制值的距离。您应该将其转换为可理解的格式
我已经实现了两种方法来检查蓝牙功能的可用性和找到我们周围可发现的设备。现在我想找到我们周围外围设备的距离。对于这些功能可以使用哪些方法以及要实现哪些代码。期待带有示例代码的解决方案
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方法得到一个大概的距离。它不会 return 任何厘米或公制值的距离。您应该将其转换为可理解的格式