【问题标题】:WARNING: The advertisement key 'Service Data' is not allowed警告:不允许使用广告密钥“服务数据”
【发布时间】:2019-10-12 09:33:20
【问题描述】:

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

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

同样的事情,我在 iOS 中也是如此。我使用 BluetoothCore 框架来实现蓝牙外设。

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

advertisementData[CBAdvertisementDataServiceDataKey] = <somedata>

但是我收到了警告:

警告:不允许使用广告密钥“服务数据”

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

【问题讨论】:

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


    【解决方案1】:

    在 iOS 上广告外设时,您不能指定服务数据。您只能指定服务 UUID 和服务名称。

    来自documentation

    advertisementData

    包含您要宣传的数据的可选字典。广告数据字典的可能键在CBCentralManagerDelegate 中有详细说明。也就是说,外围管理器对象仅支持其中两个键:CBAdvertisementDataLocalNameKeyCBAdvertisementDataServiceUUIDsKey

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

    恐怕没有解决您对 iOS 的要求的解决方案。

    【讨论】:

    • 你知道为什么苹果有这个政策吗?
    • 没有。我的猜测是,当他们实施 Core BlueTooth 时,他们只是没有看到需要它。可能还有电池效率等原因。
    • 这在Android中是可以做到的,我也不知道为什么CoreBluetooth不允许我们这样做。
    • 我也不知道,但你不知道。对不起。
    猜你喜欢
    • 2020-09-01
    • 2021-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-30
    相关资源
    最近更新 更多