ios - 警告 : The advertisement key 'Service Data' is not allowed

标签 ios bluetooth-lowenergy core-bluetooth ios-bluetooth

我正在开发 BLE 外设应用程序。根据要求,广告包必须包含服务数据字段。我在 Android 中做过,数据包应该是这样的:

enter image description here

0x16 是此处列出的服务数据字段 https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/

同样的事情,我在 iOS 中进行。我使用 BluetoothCore 框架来实现蓝牙外设。

下面是我应该用来设置服务数据字段值的属性:

advertisementData[CBAdvertisementDataServiceDataKey] = <somedata>

但是我得到了一个警告:

WARNING: The advertisement key 'Service Data' is not allowed

谁能告诉我原因以及解决方案是什么?

最佳答案

在 iOS 上宣传外围设备时,您不能指定服务数据。您只能指定服务 UUID 和服务名称。

来自documentation :

advertisementData

An optional dictionary containing the data you want to advertise. The possible keys of an advertisementData dictionary are detailed in CBCentralManagerDelegate. That said, only two of the keys are supported for peripheral manager objects: CBAdvertisementDataLocalNameKey and CBAdvertisementDataServiceUUIDsKey.

针对您的警告的解决方案是从广告数据字典中删除 CBAdvertisementDataServiceDataKey

恐怕没有满足您在 iOS 上的要求的解决方案。

关于ios - 警告 : The advertisement key 'Service Data' is not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56315371/

相关文章:

iphone - 将单个数组分成两个数组的代码如何?

android - 蓝牙信标如何与应用程序配合使用?

ios7 - 后台 iBeacon - 用例

iphone - 指向整数转换的不兼容指针将 'void *' 发送到类型为 'NSJSONReadingOptions' 的参数

ios - 在 iOS 中,使用 UIViewController 构建通用 UI 组件是一个好习惯吗?

ios - 如何在 xib View Controller 中添加图像(swift3)

ios - 当应用程序失去焦点时,基于 BLE 值的 Swift 通知

Android BLE ACL_DISCONNECTED 有时会延迟

objective-c - CBperipheral uuid 在 i-phone5 上的 ios 6.0.1 中为空

iphone - 使用核心蓝牙框架将mac mini设置为外围设备