【发布时间】:2015-03-23 14:33:57
【问题描述】:
我的应用程序作为蓝牙 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)
}
但看起来 CBAdvertisementDataManufacturerDataKey 中的数据集正在被剥离,而不是通过无线电发送出去。我已经阅读了在 Apple 文档和在线中可以找到的所有相关内容。共识似乎是核心蓝牙忽略数据,因为仅支持 CBAdvertisementDataLocalNameKey 和 CBAdvertisementDataServiceUUIDsKey。上面的编译和运行良好,我可以在我的 BT 扫描仪应用程序中“我希望这能工作”,但我的两位自定义数据似乎不起作用。
有什么办法可以规避吗? CoreBluetooth 的任何可接受的替代品或我缺少的任何完全愚蠢的东西?
谢谢,
丹
【问题讨论】:
-
你能发送一个 iBeacon 格式的广告吗?您在主要/次要字段中获得四个字节的数据。
-
除非在 iOS 8 中有所改变,否则您不能修改制造商数据:stackoverflow.com/a/23790973/2128900
标签: swift bluetooth-lowenergy core-bluetooth ios-bluetooth cbperipheralmanager