IApp
IApp

Reputation: 667

CoreBluetooth AdvertisementData doesn't contain CBAdvertisementDataLocalNameKey?

I'm currently building a CoreBluetooth application that I want to scan for available devices, the problem is that the AdvertismentData dictionary in "didDiscoverPeripheral" does not contain CBAdvertisementDataLocalNameKey - it only contains CBAdvDataChannel and CBAdvDataIsConnectable. This means that I am unable to identify my BLE device.

The interesting thing is that the Lightblue app (an iOS BLE scanner) is able to show the name and is thus presumably able to access "CBAdvertisementDataLocalNameKey".

Does anyone know what I'm doing wrong? I'm really tearing my hair out over this!

Here's a basic sample of my code:

-(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]);
}

Upvotes: 3

Views: 2764

Answers (2)

WholeCheese
WholeCheese

Reputation: 447

I don't have an answer but I can at least confirm that I am seeing the same thing in my iOS app. In fact, the advertisementData never has any data for CBAdvertisementDataTxPowerLevelKey, CBAdvertisementDataLocalNameKey, or CBAdvertisementDataManufacturerDataKey. Is this particular to Apple's implementation?

I don't see any manufacturer name data until after connecting to the peripheral and then I get a CBCharacteristic for org.bluetooth.characteristic.manufacturer_name_string

Upvotes: 0

hotpaw2
hotpaw2

Reputation: 70663

Instead of using the advertisement data, try using the name property of a discovered peripheral:

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

Upvotes: 2

Related Questions