警告:不允许使用广告密钥“服务数据" [英] WARNING: The advertisement key 'Service Data' is not allowed
问题描述
我正在开发BLE外围应用程序.根据要求,广告包必须包含服务数据"字段.我已经在Android中做到了,数据包应该是这样的:
I am developing a BLE peripheral app. By requirement, the advertising packet must contain Service Data field. I have done this in Android, the packet should be like this:
0x16是此处列出的服务数据字段 https://www .bluetooth.com/specifications/assigned-numbers/generic-access-profile/
0x16 is Service Data field listed here https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/
同一件事,我在iOS中完成.我使用BluetoothCore框架来实现蓝牙外围设备.
Same thing, I do it in iOS. I use BluetoothCore framework to implement the bluetooth peripheral.
以下是我应该用来为服务数据"字段设置值的属性:
Below is the attribute I should use to set value for Service Data field:
advertisementData[CBAdvertisementDataServiceDataKey] = <somedata>
但是我收到警告:
警告:不允许使用广告代码服务数据"
WARNING: The advertisement key 'Service Data' is not allowed
有人可以让我知道原因和解决方案吗?
Can someone let me know why and what is the solution?
推荐答案
在iOS上为外围设备做广告时,您无法指定服务数据.您只能指定服务UUID和服务名称.
You cannot specify service data when advertising a peripheral on iOS. You can only specify the service UUID and the service name.
从文档:
advertisementData
advertisementData
包含要发布的数据的可选词典. CBCentralManagerDelegate
中详细说明了advertiseData词典的可能关键字.也就是说,外围设备管理器对象仅支持两个键:CBAdvertisementDataLocalNameKey
和CBAdvertisementDataServiceUUIDsKey
.
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
.
The solution to your warning is to remove CBAdvertisementDataServiceDataKey
from the advertising data dictionary.
恐怕iOS上无法解决您的要求.
I'm afraid there isn't a solution to your requirements on iOS.
这篇关于警告:不允许使用广告密钥“服务数据"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!