HomeiOS Developmentios - Methods to promote manufacturer-specific knowledge in Swift (CoreBluetooth) like Android's...

ios – Methods to promote manufacturer-specific knowledge in Swift (CoreBluetooth) like Android’s addManufacturerData?


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

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

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

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

I am making an attempt to attain the identical in Swift utilizing the CoreBluetooth framework. I’ve seemed into CBPeripheralManager and the startAdvertising technique, which takes a dictionary of commercial knowledge.

I consider the important thing I ought to be utilizing is CBAdvertisementDataManufacturerDataKey, however I am undecided tips on how to construction the information to incorporate my MANUFACTURER_ID and the payload accurately.

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

I’ve tried


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

peripheralManager.startAdvertising(advertisementData)

Nevertheless it offers me a warning that the dictionary keys does not exist and i feel it drops the information and does not promote something. I’ve checked stack overflow and located a submit that stated IOS does not allow it, however it was virtually a decade previous. I simply wish to ship a customized byte array by way of bluetooth low power utilizing an iphone.

Any assist could be significantly appreciated!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments