重新加载蓝牙信号强度

时间:2014-06-23 05:25:11

标签: ios objective-c cocoa-touch bluetooth core-bluetooth

所以,我正在扫描蓝牙外设并记录信号强度。

- (void)viewDidLoad
{
    CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    [centralManager scanForPeripheralsWithServices:nil options:nil];
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSLog(@"Peripheral Discovered");
    NSLog(@"%ld", (long)RSSI.integerValue);
}

方法 centralManager:didDiscoverPeripheral:advertisementData:RSSI:我可以访问RSSI号码(信号强度)。

最接近实时更新此值的最佳方法是什么?!

我应该设置一个计时器并在每个 X 秒内调用 scanForPeripheralsWithServices 吗?我应该实现某种递归回调吗?

有没有更好的方法来获得外设信号强度?

1 个答案:

答案 0 :(得分:3)

您可以定期在CBPeripheral对象上调用readRSSI方法。

  

<强>讨论

     

当您调用此方法来检索外围设备的RSSI时   它目前连接到中央管理器,外围设备呼叫   peripheralDidUpdateRSSI:error:其委托对象的方法。如果   您可以成功检索外围设备的RSSI值   通过外围设备的RSSI属性访问它。