CBAdvertisementDataLocalNameKey

CBAdvertisementDataLocalNameKey

我当前正在构建一个CoreBluetooth应用程序,我想扫描可用设备,问题是“didDiscoverPeripheral”中的AdvertismentData词典不包含CBAdvertisementDataLocalNameKey-它仅包含CBAdvDataChannel和CBAdvDataIsConnectable。这意味着我无法识别我的BLE设备。

有趣的是,Lightblue应用程序(iOS BLE扫描仪)能够显示名称,因此大概可以访问“CBAdvertisementDataLocalNameKey”。

有人知道我在做什么错吗?我真的在为此扯头发!

这是我的代码的基本示例:

-(void)scan
{

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber  numberWithBool:YES], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
    [mCentralManager scanForPeripheralsWithServices:nil options:options];
}

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    for(id key in advertisementData)
        NSLog(@"key=%@ value=%@", key, [advertisementData objectForKey:key]);
}

最佳答案

代替使用广告数据,请尝试使用发现的外围设备的name属性:

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
    NSString    *thePeripheralName  = peripheral.name;
}

关于ios - CoreBluetooth AdvertisementData不包含CBAdvertisementDataLocalNameKey吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29486069/

10-10 20:47