相关疑难解决方法(0)

核心蓝牙 - 范围内设备的不断RSSI更新

我刚刚开始使用iOS的核心蓝牙框架,我正在开发一个需要不断扫描BLE设备的应用程序,以便我可以每分钟检索一次RSSI编号.

目前我有:

manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
[manager scanForPeripheralsWithServices:nil options:options];
Run Code Online (Sandbox Code Playgroud)

这启动我的应用程序扫描BLE设备并在发现设备时调用此委托方法:

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSLog(@"Did discover peripheral. peripheral: %@ rssi: %@, UUID: %@ advertisementData: %@ ", peripheral, RSSI, peripheral.UUID, advertisementData);
    //Do something when a peripheral is discovered.

    rssiLabel.text = [RSSI stringValue];

    [manager retrievePeripherals:[NSArray arrayWithObject:(id)peripheral.UUID]];}
Run Code Online (Sandbox Code Playgroud)

这个方法得到我可以显示的外围设备的RSSI号码.最后一行然后调用此委托方法:

- (void) centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals {

    NSLog(@"Currently known peripherals :");
    int i = 0;
    for(CBPeripheral *peripheral in peripherals) …
Run Code Online (Sandbox Code Playgroud)

ios ios5 core-bluetooth

14
推荐指数
1
解决办法
2万
查看次数

如何在 iOS9 中获取 RSSI

我有显示几个警告的 BLE 源代码,我是 BLE 的新手。请看下面的代码。我曾尝试用 readRSSI 替换,但告诉我我无法将 Int 与 Void 进行比较。如何获得 readRSSI 的 Int 值?或者我应该如何更改代码?

- (void)peripheralDidUpdateRSSI:(CBPeripheral * _Nonnull)peripheral error:(NSError * _Nullable)error
{
    if (!isConnected)
        return;
    if (rssi != peripheral.RSSI.intValue)
    {
        rssi = peripheral.RSSI.intValue;
        [[self delegate] bleDidUpdateRSSI:activePeripheral.RSSI];
    }
}
Run Code Online (Sandbox Code Playgroud)

*rssi 是一个静态整数。

*isConnected 是一个布尔值。

编辑:问题是自 iOS 8.0 起不推荐使用 RSSI。

objective-c ios core-bluetooth ios9

0
推荐指数
1
解决办法
1870
查看次数

标签 统计

core-bluetooth ×2

ios ×2

ios5 ×1

ios9 ×1

objective-c ×1