本文介绍了如何在Xamarin iOS中使用蓝牙低能耗协议来宣传制造商特定的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Xamarin iOS中使用低功耗蓝牙协议广播包含某些特定于制造商特定数据的广告包。我可以广播广告数据包,但是当收到它们时,它们将不包含任何制造商特定的数据。它们确实包含我正在设置的本地名称和数据服务UUID密钥。我应该提到在Xamarin Android中这样做不是问题。您能告诉我为什么Xamarin iOS中不广播制造商特定数据吗?我正在使用以下代码:

I need to broadcast advertisement packets which contain certain manufacturer specific data using Bluetooth low energy protocol in Xamarin iOS. I am able to broadcast advertising packets, but when they are received they contain no manufacturer specific data. They do contain local name and data service UUID key which I'm setting. I should mention doing this in Xamarin Android is not a problem. Could you please tell me why manufacturer specific data is not being broadcast in Xamarin iOS? I am using the following code:

using CoreBluetooth;

namespace XamarinBt
{
    public class BluetoothOperations
    {
          CBPeripheralManager cbPeriphMang = new CBPeripheralManager();
          public void AdvertiseData()
          {
                var uui = new CBUUID[] { CBUUID.FromString("E20A39F4-73F5-4BC4-A12F-17D1AD07A961") };
                var nsArray = NSArray.FromObjects(uui);
                var nsObject = NSObject.FromObject(nsArray);

                var manufacturerDataBytes = new byte[6] { 5, 255, 76, 0, 25, 35 };

                var advertisementData = new NSDictionary(
                     CBAdvertisement.DataLocalNameKey, "id1",
                     CBAdvertisement.DataServiceUUIDsKey, nsObject,
                     CBAdvertisement.DataManufacturerDataKey, NSData.FromArray(manufacturerDataBytes));

                if(cbPeriphMang.Advertising) cbPeriphMang.StopAdvertising();

                cbPeriphMang.StartAdvertising(advertisementData);
          }
    }
}


推荐答案

不幸的是,您不能在广告中指定制造商数据。

Unfortunately, you can't specify manufacturer data in the advertisement.

来自:

包含要发布的数据的可选字典。 $ data $ b 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.

这篇关于如何在Xamarin iOS中使用蓝牙低能耗协议来宣传制造商特定的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:41