小编kj1*_*ett的帖子

核心蓝牙 - 范围内设备的不断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万
查看次数

标签 统计

core-bluetooth ×1

ios ×1

ios5 ×1