gpt4 book ai didi

ios - 我是否必须等待 Swift 中的 didReadRSSI() 函数?

转载 作者:行者123 更新时间:2023-11-29 12:13:05 24 4
gpt4 key购买 nike

我想发现我所在区域的 BLE 设备并存储它们当前的 RSSI 值。发现是有效的,但我注意到,如果我的函数 didDiscoverPeripheral 真的保存了......我认为我应该在离开 之前等待 didReadRSSI func >didDiscoverPeripheral。但是我怎样才能以一种简单的方式意识到这一点并且我的意见是正确的呢?

    func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber)
{
CBperipheral = [peripheral]

peripheral.readRSSI()
}

func peripheral(peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: NSError?)
{
//Store the peripheral specific RSSI, Name and identifier
}

最佳答案

我会建议这样的事情-

var peripherals = Set<CBPeripheral>
var peripheralRSSIs = Dictionary<CBPeripheral,NSNumber>()


func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber)
{
self.peripherals.insert(peripheral)
self.peripheralRSSIs[peripheral]=RSSI
central.connectPeripheral(peripheral,options:nil) // Connect if you want to be able to retrieve additional RSSI values
}

func centralManager(_ central: CBCentralManager,
didConnectPeripheral peripheral: CBPeripheral)
{
peripheral.delegate=self
peripheral.readRSSI()
}

func peripheral(peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: NSError?)
{
if (error != nil) {
print(error)
} else {
self.peripheralRSSIs[peripheral]=RSSI
}
}

关于ios - 我是否必须等待 Swift 中的 didReadRSSI() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32792664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com