BLE scan response sometimes doesn't include kCBAdvDataLocalName

I'm developing iOS application which works as BLE central.
I have a question about the scan response information.

My application is working in foreground and executing scanForPeripheralsWithService:options() in every 3 seconds repeatedly.


[_centralMgr scanForPeripheralsWithServices:nil
                                        options:nil];


In almost all case, when didDiscoverPeripheral() is called, my application can get the localName of the peripheral with the key @"kCBAdvDataLocalName".
(The peripheral device is developed by other vendor)

Below is the NSLog output of didDiscoverPeripheral() with localName.


[MyApp] <Warning>: (-[MyBleCentralMgr centralManager:didDiscoverPeripheral:advertisementData:RSSI:])
    [name:DeviceName], [state:0], [identifier:240FF7D3-45D5-C4EE-2E96-BED578225C56]
[MyApp] <Warning>: (-[MyBleCentralMgr centralManager:didDiscoverPeripheral:advertisementData:RSSI:]) RSSI=-63, advertisementData={
        kCBAdvDataChannel = 39;
        kCBAdvDataIsConnectable = 1;
        kCBAdvDataLocalName = "DeviceName";
        kCBAdvDataManufacturerData = <[manufactorer data of peripheral device]>;
    }


But sometimes(in rare case), the scan response doesn't have localName.
(But it has another name in [peripheral.name])

Below is the NSLog out of didDiscoverPeripheral() without localName.

[MyApp] <Warning>: (-[MyBleCentralMgr centralManager:didDiscoverPeripheral:advertisementData:RSSI:])
    [name:DeviceName], [state:0], [identifier:240FF7D3-45D5-C4EE-2E96-BED578225C56]
[MyApp] <Warning>: (-[MyBleCentralMgr centralManager:didDiscoverPeripheral:advertisementData:RSSI:]) RSSI=-63, advertisementData={
        kCBAdvDataChannel = 39;
        kCBAdvDataIsConnectable = 1;
        kCBAdvDataManufacturerData = <[manufactorer data of peripheral device]>;
    }


The engineer of peripheral device says "I'm always including localName in scan response".

If anyone have information about my questions, please let me know.

  1. Is this phenomenon possible ?(localName disappears from scan response)
  2. What is the difference of localName advertisementdata and peripheral.name

I appreciate any feedback. Thank you.

Accepted Answer

It is possible that didDiscoverPeripheral will be called more than once for the same peripheral if the peripheral sends more data in separate packets.

If the peripheral is not including the name in the advertising packet, but in the scan response instead, you will first get a callback with no name, and a second callback with the name and any additional info (as long as iOS is in active scanning mode with your app in the foreground)


Another explanation would be the cached GAP name. Each BLE device has 2 places where a "name" is defined. The advertised name and the GAP name.

If the peripheral has never been connected to the iOS device before, iOS will report the advertised name found in the scan response.

Once the peripheral is connected, it will obtain the GAP name and cache it. At future discoveries, it will report this cached GAP name instead.


This allows for iOS to report a name even when it is in passive scan mode when your app is in the background or the phone is locked.

@Gualtier


Thanks for your replay.

My understanding is below, are they correct ?


  • "Name in advertising packet" is "localName which I can get with a key kCBAdvDataLocalName"
  • "GAP name" is "paripheral.name"
  • iOS application can not identify advertising packet and scan response(Because iOS application can use only didDiscoverPeripheral() API.)


GAP name(= peripheral.name) will be cached,

so if the name is changed in peripheral side, it causes the difference between peripheral sending GAP name and central(iOS app.) received GAP name.


Actually my iOS application need to display the name of peripheral device, and it could be changed by user operation on peripheral side.

So I'll use the localName in advertising packet. and not use the GAP name(= peripheral.name)

And when there is no localName in didDiscoverPeripheral, I don't update the device name displayed in my application.


Thank you.

BLE scan response sometimes doesn't include kCBAdvDataLocalName
 
 
Q