WARNING: The advertisement key 'Service Data' is not allowed
Asked Answered
L

1

6

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:

enter image description here

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?

Leisured answered 26/5, 2019 at 16:28 Comment(0)
W
5

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.

Wachtel answered 26/5, 2019 at 21:18 Comment(4)
Do you know why Apple has that policy?Leisured
No. My guess would be they just didn’t see a need for it when they implemented Core BlueTooth. There may also be reasons of battery efficiency etc.Wachtel
this is able to do in Android, I also have no idea why CoreBluetooth doesn't allow us to do.Leisured
I don't know either, but you can't. Sorry.Wachtel

© 2022 - 2024 — McMap. All rights reserved.