Expose localName of advertising packets in ScanResult object
See original GitHub issueIs your feature request related to a problem? Please describe.
When a BLE peripheral is discovered the first time by an iOS device the localName
from the advertising packet is shown to the user as device name.
After connecting to this device the GAP name is discovered and cached.
For subsequent connection attempts the cached GAP name is shown to the user instead of the localName
in the advertising packet.
If you are using the requestDevice(...)
function of this plugin a dialog is opened automatically which shows eventually cached names.
If you have a BLE device where the GAP name differs from the localName
provided in the advertising packets you can not guarantee a proper user experience using the requestDevice(...)
function.
By using the requestLEScan(...)
function you could provide a proper user experience by fetching the localName
from the advertising packet of each found device and render your own connection dialog.
Unfortunately the localName
attribute is currently not accessible in the ScanResult object.
Describe the solution you’d like
Add the localName
property from the advertising packet to the ScanResult object.
Additional context
I tested it out by adding the following snippet to the getScanResult()
function of the Plugin.swift
file right before the return
Statement:
let localName = advertisementData[CBAdvertisementDataLocalNameKey] as? String
if localName != nil {
data["localName"] = localName
}
But I am not sure if localName
is a good attribute name next to the device.name
which is already present in the ScanResult
. Personally, I would prefer a name that makes it clear that it is the name from the advertisement packet.
Do you think this is something you could add to this plugin? Thank you in advance for your time and efforts!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I agree that the larger response doesn’t really matter and that it’s best if both
localName
anddevice.name
are there on all platforms. I don’t see any other drawbacks and will go with that solution.Thanks for the fruitful discussion.
This has been added to v0.4.0 (Capacitor 2) and v1.0.0-1 (Capacitor 3).