Home > Net >  How to set an advertisement payload and a scan response payload on an iOS Peripheral using CoreBluet
How to set an advertisement payload and a scan response payload on an iOS Peripheral using CoreBluet

Time:01-06

I've implemented similar functionality on Android using and it works cleanly and I'm able to grab the advertisement payload & scan response payload with this API defined in android.bluetooth.le.AdvertiseData package.

AdvertiseData.Builder()
            .setIncludeDeviceName(false)
            .addServiceUuid(uuid)
            .addServiceData(uuid, data)

and I'm able to use this to get scan response payload and advertisement payload cleanly and reliably if I start advertising like this assuming advtData & scanRespData payloads are defined using the above code snippet

obj.startAdvertising(advCfg, advtData,scanRespData, advtCallback)

with this I'm able to clearly express and advertise an Android peripheral while also exposing the advertisement payload and the scan response payload separately and with their respective UUIDs.

I was looking to get the same done in iOS & I've looked into the following and I don't have a working solution yet.

  • peripheralManager.startAdvertising(...): here I can only set the Device Local name, the advertising does happen but the scan response payload and advertisement payload are null on Android; I was expecting that iOS would have certain builder APIs that would expose some meaningful information on scan response and advertisement payload, but this is clearly not the one
  • exposing a read-only characteristic against a service UUID: while this would help expose the data payload, it wouldn't be visible until the connection has been established and it isn't what I'd like for my peripheral
  • setting overflow key in peripheralManager.startAdvertising 's dictionary; this results in a warning and this isn't an error; the advertising happens, but no relevant payload is exposed & if I set the key to a hashmap of CBUUID:NSData I get an IllegalArgumentException;
  • setting deviceLocalName key: a local name key looks like a good middle ground but I'd prefer a different scan

Let me know if I'm missing something or this is something Apple's CoreBluetooth lacks this feature altogether.

CodePudding user response:

Advertising service data is currently impossible on iOS, see this discussion: WARNING: The advertisement key 'Service Data' is not allowed

Despite Apple has documentation for CBAdvertisementDataServiceDataKey, it's not supported in startAdvertising method.

  • Related