Search code examples
swiftbluetooth-lowenergycore-bluetooth

Advertisement data shows 3 services, but there is only one discovered


I use CBCentralManager to connect to BLE peripheral. It connects with this advertisement data:

["kCBAdvDataLocalName": name, 
"kCBAdvDataIsConnectable": 1, 
"kCBAdvDataServiceUUIDs": <__NSArrayM 0x600000c74de0>(
Generic Access Profile,
Generic Attribute Profile,
1803
),
"kCBAdvDataChannel": 37]

so I call peripheral.discoverServices(nil) to get this 3 services, but didDiscoverServices only finds one

 [<CBService: 0x600001768040, isPrimary = NO, UUID = 1803>]

Can anyone clarify why is it like that?


Solution

  • Two of the the three services you see in the advertisement are the Generic Access Profile and the Generic Attribute Profile. These are used to manage the discovery of peripherals and the discovery of services and attributes.

    Core Bluetooth uses these services when you request peripheral, service and characteristic discovery.

    You cannot interact with them directly and so they are not reported to your delegate when you discover available services.

    The final service that your peripheral exposes is the link loss service (0x1803). This service does have a characteristic that your central can interact with, and so it is returned when you discover services.