WARNING: The advertisement key 'Service Data&#

2020-07-17 15:33发布

问题:

I am developing a BLE peripheral app. By requirement, the advertising packet must contain Service Data field. I have done this in Android, the packet should be like this:

0x16 is Service Data field listed here https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/

Same thing, I do it in iOS. I use BluetoothCore framework to implement the bluetooth peripheral.

Below is the attribute I should use to set value for Service Data field:

advertisementData[CBAdvertisementDataServiceDataKey] = <somedata>

However I got a warning:

WARNING: The advertisement key 'Service Data' is not allowed

Can someone let me know why and what is the solution?

回答1:

You cannot specify service data when advertising a peripheral on iOS. You can only specify the service UUID and the service name.

From the documentation:

advertisementData

An optional dictionary containing the data you want to advertise. The possible keys of an advertisementData dictionary are detailed in CBCentralManagerDelegate. That said, only two of the keys are supported for peripheral manager objects: CBAdvertisementDataLocalNameKey and CBAdvertisementDataServiceUUIDsKey.

The solution to your warning is to remove CBAdvertisementDataServiceDataKey from the advertising data dictionary.

I'm afraid there isn't a solution to your requirements on iOS.