private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
// We can obtain various information about the advertisement we just received by accessing
// the properties of the EventArgs class
// The timestamp of the event
DateTimeOffset timestamp = eventArgs.Timestamp;
// The type of advertisement
BluetoothLEAdvertisementType advertisementType = eventArgs.AdvertisementType;
// The received signal strength indicator (RSSI)
Int16 rssi = eventArgs.RawSignalStrengthInDBm;
// The local name of the advertising device contained within the payload, if any
string localName = eventArgs.Advertisement.LocalName;
// Get iBeacon specific data
var beaconData = eventArgs.Advertisement.iBeaconParseAdvertisement(eventArgs.RawSignalStrengthInDBm);
if (beaconData == null)
return;
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
var existing = beacons.Where(b => b.UUID == beaconData.UUID && b.Major == beaconData.Major && b.Minor == beaconData.Minor).FirstOrDefault();
if (existing != null)
{
var idx = beacons.IndexOf(existing);
beacons.RemoveAt(idx);
beacons.Insert(idx, beaconData);
}
else
beacons.Add(beaconData);
});
}