我的应用程序作为蓝牙 LE 外围设备运行,我试图在广告中发送几个字节的自定义数据。
func btStartBroadcasting(peripheral: CBPeripheralManager!) {
// create an array of bytes to send
var byteArray = [UInt8]()
byteArray.append(0b11011110); // 'DE'
byteArray.append(0b10101101); // 'AD'
// convert that array into an NSData object
var manufacturerData = NSData(bytes: byteArray,length: byteArray.count)
// define a UIUD for the service
let theUUid = CBUUID(NSUUID: uuid)
// build the bundle of data
let dataToBeAdvertised:[String: AnyObject!] = [
CBAdvertisementDataLocalNameKey : "I wish this worked",
CBAdvertisementDataManufacturerDataKey : manufacturerData,
CBAdvertisementDataServiceUUIDsKey : [theUUid],
]
peripheral.startAdvertising(dataToBeAdvertised)
}
Run Code Online (Sandbox Code Playgroud)
但 CBAdvertisementDataManufacturerDataKey 中的数据集似乎被删除并且没有通过无线电发送出去。我已经阅读了苹果文档和网上能找到的所有关于此问题的小片段。共识似乎是核心蓝牙忽略数据,因为仅支持 …
core-bluetooth bluetooth-lowenergy ios-bluetooth swift cbperipheralmanager