What's the difference between peripheral.name and advertisementData(kCBAdvDataLocalName)???
From - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *, id> *)advertisementData RSSI:(NSNumber *)RSSI;
As far as I know, advertisementData(kCBAdvDataLocalName) is Scan Response Data.
This comes after Scan Response Request.
However, what does peripheral.name mean??
Is there any GENERAL TERM?? such as scan response data.
Apple document says that peripheral.name is device advertises or GAP device name.
If it(peripheral.name) is device advertises, what is the difference from scan response data??
This is definition from Apple Doc for peripheral.name.
The value of this property is a string containing the device name of the peripheral. You can access this property to retrieve a human-readable name of the peripheral. There may be two types of names associated with a peripheral: one that the device advertises and another that the device publishes in its database as its Bluetooth low energy Generic Access Profile (GAP) device name. Although this property may contain either type of name, the GAP device name takes priority. This means that if a peripheral has both types of names associated with it, this property returns its GAP device name.
As the documentation indicates, the peripheral.name property may contain either of the names (advertising, or GAP) under different conditions.
- When a peripheral is first discovered, (and if iOS is in active scan at the time), the .name property will contain advertisementData(kCBAdvDataLocalName)
- If you connect to this peripheral after this discovery, the GAP name will be read and it will be cached. At this point the .name property will contain the GAP name
- On subsequent discoveries of the same peripheral, if it is still in the cache, even before connecting, the .name property will now keep showing the GAP name instead of what is being advertised at the time. Once the GAP name is cached, the .name property will be available even if iOS is in passive scan)
- If the GAP name changes and you want this to be reflected in the .name property, you should employ the Service Changed Characteristic, so iOS will read the GAP name (among ither things) again and update the .name property.
Notes:
- how long a peripheral will stay cached is variable depending on numerous factors. It is not possible to determine the time, or force any actions on the cache through an app. Service Change Characteristic is the proper mechanism for this
- Active vs Passive scan means whether iOS is asking for Scan Response Data or not. If your app is active in the foreground, you can rely on active scans. If your app is in the background, the screen locked, and the phone has been idle for a while, iOS may choose to go to passive scan. If a peripheral is encountered for the first time when iOS is in passive scan, the .name property will be empty even if the local name is being advertised in the scan response.