How to advertise manufacturer specific data using bluetooth low energy protocol in Xamarin iOS?

六眼飞鱼酱① 提交于 2020-01-03 05:36:05

问题


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);
          }
    }
}

回答1:


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

From the 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.



来源:https://stackoverflow.com/questions/46364443/how-to-advertise-manufacturer-specific-data-using-bluetooth-low-energy-protocol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!