gpt4 book ai didi

ios - corebluetooth 读取 RSSI 错误 :The operation was cancelled

转载 作者:可可西里 更新时间:2023-11-01 03:21:26 25 4
gpt4 key购买 nike

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

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

我设置了一个定时读取RSSI的函数,定时器代码如下

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

下面是检测RSSI的代码

- (void)detectRSSI
{
[self.peripheral readRSSI];
}

那么问题是,

该函数工作正常,但是当我将时间间隔设置为小于 1.2 秒时,

peripheralDidUpdateRSSI 会随机报这样的错误信息:

The operation was cancelled.

如果速率超过 1.2 秒,则不会发生。

有没有人知道更频繁地读取 RSSI 值(0.5 秒或更短)?

最佳答案

我也遇到了同样的问题。对我来说,只要在 peripheralDidUpdateRSSI 中添加 sleep(2) 就可以了。只是不要忘记在初始化 CBCentralManager 时使用后台队列。

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

关于ios - corebluetooth 读取 RSSI 错误 :The operation was cancelled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15540481/

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