Discovered Peripheral name is Nil
Describe the bug
I have a Bluetooth device that advertises it's name.
When running a scan/discovery with plain old CoreBluetooth i receive a CBPeripheral with the correct name in its name property.
When using RxBluetoothKit for scan/discovery on the same device i receive a nil value for the name property.
To Reproduce Steps to reproduce the behaviour:
- Scan for a device that advertises its name
- Receive
RxBluetoothKit.ScannedPeripheral, indicating the successful discovery - The underlying
RxBluetoothKit.Peripheraldoes not contain a value in thenameproperty. Also the wrappedRxBluetoothKit.Peripheral.CBPeripheralin this object does not contain a value in its ownnameproperty.
Expected behaviour The name property should contain the name of the device.
Please note the different behaviour using the CBManagerDelegate:
When performing a discovery via Apple's CoreBluetooth the CBPeripheral in the centralManager(_:didDiscover:advertisementData:rssi:) delegate callback has a valid value in it's name property
Environment:
- Device: [iPhone 6 - iPhone X]
- OS: [iOS 12]
- Library version [5.1.4]
- Swift version [4.0 - 4.2]
Further information
If add a delay of around 100ms before accessing the name property i am finally able to read the name.
I noticed, that the name is only missing in the first advertisement for each peripheral received by scanForPeripheral. This should definitely be fixed.
A workaround for now would be to use CBCentralManagerScanOptionAllowDuplicatesKey to allow receiving multiple advertisements for one peripheral, and skipping the ones without a name.
scanForPeripherals(withServices: services, options: [CBCentralManagerScanOptionAllowDuplicatesKey: true])
.skipWhile({ (peripheral) -> Bool in
return peripheral.peripheral.name == nil
})
This is caused by the iOS vanilla API that may populate name at a later time depending on how it was obtained. The library does not know if a particular peripheral will have a name so I do not expect this issue to be fixable. There may be an additional API for name updates though I suppose. We will get back to this issue next week probably