How to advertise manufacturer specific data using

2019-06-12 14:25发布

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条回答
\"骚年 ilove
2楼-- · 2019-06-12 14:56

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.

查看更多
登录 后发表回答