RxBluetoothKit icon indicating copy to clipboard operation
RxBluetoothKit copied to clipboard

Discovered Peripheral name is Nil

Open PaulEhrhardt opened this issue 7 years ago • 3 comments

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:

  1. Scan for a device that advertises its name
  2. Receive RxBluetoothKit.ScannedPeripheral, indicating the successful discovery
  3. The underlying RxBluetoothKit.Peripheral does not contain a value in the name property. Also the wrapped RxBluetoothKit.Peripheral.CBPeripheral in this object does not contain a value in its own name property.

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]

PaulEhrhardt avatar Nov 07 '18 12:11 PaulEhrhardt

Further information If add a delay of around 100ms before accessing the name property i am finally able to read the name.

PaulEhrhardt avatar Nov 07 '18 14:11 PaulEhrhardt

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
    })

Michael-Bischof avatar Nov 08 '18 13:11 Michael-Bischof

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

dariuszseweryn avatar Jan 11 '19 12:01 dariuszseweryn