corebluetooth读取RSSI错误:操作已取消

mom*_*oyo 8 rssi ios core-bluetooth bluetooth-lowenergy xcode4.5

我正在使用Corebluetooth框架开发一个应用程序,

并连接到BLE设备以获取RSSI值.

我设置了一个定期读RSSI的功能,定时器代码如下

NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:1.2f target:self selector:@selector(detectRSSI) userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

并且detectRSSI代码如下

- (void)detectRSSI
{
    [self.peripheral readRSSI];
}
Run Code Online (Sandbox Code Playgroud)

所以问题是,

该功能工作正常,但当我设置时间间隔小于1.2秒时,

peripheralDidUpdateRSSI会随机报告错误信息,如下所示:

The operation was cancelled.
Run Code Online (Sandbox Code Playgroud)

如果速率超过1.2秒就不会发生.

有没有人有任何想法更频繁地读取RSSI值(0.5秒或更短)?

sch*_*stz 0

我也遇到同样的问题。对我来说,当我简单地添加sleep(2)inside时它就起作用了peripheralDidUpdateRSSI。只是不要忘记在初始化 CBCentralManager 时使用后台队列。

- (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(NSError *)error
{
    NSLog(@"RSSI = %@", peripheral.RSSI);
    sleep(2);
    [self.connectedPeripheral readRSSI];
}
Run Code Online (Sandbox Code Playgroud)