Я пытаюсь объявить UUID в своем приложении UWP с помощью BLE, чтобы другие устройства могли его найти и найти.Вот мой код для рекламы:
// Start advertisement
if (_publisher == null)
{
_publisher = new BluetoothLEAdvertisementPublisher();
}
// We need to add some payload to the advertisement. A publisher without any payload
// or with invalid ones cannot be started. We only need to configure the payload once
// for any publisher.
// Add a manufacturer-specific section:
// First, let create a manufacturer data section
var manufacturerData = new BluetoothLEManufacturerData();
// Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
manufacturerData.CompanyId = 0xFFFE;
// Finally set the data payload within the manufacturer-specific section
// Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)
var writer = new DataWriter();
UInt16 uuidData = 0x1234;
writer.WriteUInt16(uuidData);
// Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.
manufacturerData.Data = writer.DetachBuffer();
// Add the manufacturer data to the advertisement publisher:
_publisher.Advertisement.ManufacturerData.Add(manufacturerData);
string serviceUuid = $"11111111-1234-1234-1234-000000000000";
_advertisementUuid = new Guid(serviceUuid);
_publisher.Advertisement.ServiceUuids.Add(_advertisementUuid);
_publisher.StatusChanged -= Publisher_StatusChanged;
_publisher.StatusChanged += Publisher_StatusChanged;
_publisher.Start();
Выдает это исключение, когда я звоню Start()
:
Данные недействительны - обнаружена недопустимая полезная нагрузка рекламы