Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]);
}
like image 744
IApp Avatar asked Mar 03 '26 23:03

IApp


1 Answers

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;
}
like image 132
hotpaw2 Avatar answered Mar 05 '26 13:03

hotpaw2