[CoreBluetooth] peripheral.name cached and not updating after peripheral changes

We are working with Bluetooth peripherals using CoreBluetooth, and I've noticed that the CBPeripheral.name property seems to be cached. Has anyone else encountered this behavior?

  1. Is this caching expected behavior in CoreBluetooth?
  2. Is there a recommended way to force refresh or invalidate the cached name?
  3. Most importantly: Is there a reliable method to get the most accurate and up-to-date name of a peripheral?

Yes, there is caching involved, but it is not a simple caching of a name, as it seems.

BLE peripherals have 2 separate name fields. One is the Advertised Name, and the other is GAP Name.

When a peripheral has never been encountered before, CoreBluetooth will report the Advertised Name as the .name property. Once this peripheral is connected to, the GAP name (along with all the other attributes) will be read and and cached, and from that point on the .name property will report the cached GAP name.

The methods to refresh will depend on which name you are trying to refresh, and how the peripheral was connected.

If the peripheral just has a simple connection, the cache is not permanent. The peripheral will fall off the cache at some point in the future depending on how many devices are encountered and cached.

If the peripheral is paired/bonded, the cache is more permanent, but it is possible to "forget" these peripherals from Settings -> Bluetooth.

The BLE way of forcing the peripheral attributes to be read again upon a later connection, rather than using cached information is to implement the "Service Changed Characteristic" (https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html#UUID-6ee92321-3db4-dad2-554e-946a80ff7435)

If the peripheral notifies the central with this characteristic then the attribute table will be re-read instead of using cached values.

If the peripheral has been paired/bonded, you can "Forget" it from Settings.

Thanks for the clarification regarding the caching behavior of CBPeripheral.name. We now understand that:

  1. CBPeripheral.name initially reflects the Advertised Name.
  2. After connection, it switches to the GAP Name, which is then cached.

Given this, we would like to ask some more questions as follows:

  1. Is there a reliable way to explicitly retrieve the current Advertised Name (not the cached GAP Name)?
  2. Can we access the advertised name directly from the advertisement data during scanning?
  3. Are there any best practices for handling peripherals that frequently change their name (e.g., dynamic naming based on state)?

Any code snippets or implementation tips would be greatly appreciated! Thanks again for the insights.

[CoreBluetooth] peripheral.name cached and not updating after peripheral changes
 
 
Q