NordicSemiconductor / IOS-CoreBluetooth-Mock

Mocking library for CoreBluetooth framework.
BSD 3-Clause "New" or "Revised" License
225 stars 51 forks source link

Simulated peripheral name always nil #78

Closed lumo2707 closed 1 year ago

lumo2707 commented 1 year ago

When I am trying to simulate peripherals the name of the retrieved device is always nil.

What I did so far:

  1. Create a mock peripheral
 let mockGateway1 = CBMPeripheralSpec
                .simulatePeripheral(proximity: .near)
                .advertising(
                    advertisementData: [
                        CBMAdvertisementDataLocalNameKey    : "mock1",
                        CBMAdvertisementDataServiceUUIDsKey : [CBMUUID(string: "f9505467-a5c5-42c2-95c8-0ec77aeXXXX")],
                        CBMAdvertisementDataIsConnectable   : true as NSNumber
                    ],
                    withInterval: 0.250,
                    alsoWhenConnected: false)
                .connectable(
                    name: "mock1",
                    services: [],
                    delegate: nil,
                    connectionInterval: 0.150,
                    mtu: 23)
                .build()
  1. Call simulatePeripherals and `simulateInitalState:
         CBMCentralManagerMock.simulatePeripherals([mockGateway1])
            CBMCentralManagerMock.simulateInitialState(.poweredOn)
  1. Then in didDiscover delegate I got one peripheral, but its name is always nil:

image

What did I wrong?

philips77 commented 1 year ago

Hmm.. i need to check that. Your still can get the name from advertising data map with CBMAdvertisementDataLocalNameKey key, that should work.

philips77 commented 1 year ago

OK, I managed to replicate the issue. Sorry for the long delay.

lumo2707 commented 1 year ago

No problem, in the meantime I use the CBMAdvertisementDataLocalNameKey as workaround.