ios – Find out how to promote manufacturer-specific information in Swift (CoreBluetooth) like Android’s addManufacturerData?

0
1
ios – Find out how to promote manufacturer-specific information in Swift (CoreBluetooth) like Android’s addManufacturerData?


I’m engaged on a Bluetooth Low Vitality (BLE) utility for iOS and I want to copy the promoting conduct from an present Android utility.

Within the Android (Kotlin) model, the promoting information is configured like this:

val confirmationAdvertiseData = AdvertiseData.Builder()
            .setIncludeDeviceName(false)
            .addManufacturerData(MANUFACTURER_ID, payload)
            .construct()

This code creates an commercial packet that doesn’t embrace the gadget’s identify however does embrace customized manufacturer-specific information. MANUFACTURER_ID is a 16-bit identifier assigned by the Bluetooth SIG, and payload is a byte array of customized information.

I am attempting to realize the identical in Swift utilizing the CoreBluetooth framework. I’ve appeared into CBPeripheralManager and the startAdvertising technique, which takes a dictionary of commercial information.

I imagine the important thing I needs to be utilizing is CBAdvertisementDataManufacturerDataKey, however I am unsure the best way to construction the info to incorporate my MANUFACTURER_ID and the payload appropriately.

How can I assemble the commercial information dictionary in Swift to copy the performance of the Kotlin code above, particularly setting the manufacturer-specific information?

I’ve tried


let advertisementData: [String: Any] = [
    CBAdvertisementDataManufacturerDataKey: manufacturerData,
    CBAdvertisementDataLocalNameKey: payload 
]

peripheralManager.startAdvertising(advertisementData)

However it provides me a warning that the dictionary keys does not exist and i believe it drops the info and does not promote something. I’ve checked stack overflow and located a publish that stated IOS does not allow it, but it surely was virtually a decade outdated. I simply wish to ship a customized byte array by way of bluetooth low vitality utilizing an iphone.

Any assist could be enormously appreciated!

LEAVE A REPLY

Please enter your comment!
Please enter your name here