void OnDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { BLEPeripheral peripheral = null; foreach (BLEPeripheral blep in discoveredPeripherals) { if (blep.UUID.StringValue.Equals(e.Peripheral.ToString())) { peripheral = blep; break; } } if (peripheral == null) { peripheral = new BLEPeripheral(e.Peripheral); discoveredPeripherals.Add(peripheral); } EventHandler <BLEDiscoveredPeripheralEventArgs> handler = DiscoveredPeripheral; if (handler != null) { BLEDiscoveredPeripheralEventArgs args = new BLEDiscoveredPeripheralEventArgs(); args.AdvertisementData = new List <KeyValuePair <string, string> > (); args.Peripheral = peripheral; args.RSSI = e.RSSI.Int32Value; foreach (KeyValuePair <NSObject, NSObject> kvp in e.AdvertisementData) { args.AdvertisementData.Add(new KeyValuePair <string, string> (kvp.Key.ToString(), kvp.Value.ToString())); } handler(this, args); } }
public override void OnScanResult(ScanCallbackType callbackType, ScanResult result) { base.OnScanResult(callbackType, result); BLEPeripheral peripheral = null; foreach (BLEPeripheral blep in discoveredPeripherals) { if (blep.UUID.StringValue == result.Device.Address) { peripheral = blep; break; } } if (peripheral == null) { peripheral = new BLEPeripheral(result.Device); peripheral.Connected += OnPeripheralConnected; peripheral.Disconnected += OnPeripheralDisconnected; discoveredPeripherals.Add(peripheral); } EventHandler <BLEDiscoveredPeripheralEventArgs> handler = DiscoveredPeripheral; if (handler != null) { BLEDiscoveredPeripheralEventArgs args = new BLEDiscoveredPeripheralEventArgs(); args.AdvertisementData = new List <KeyValuePair <string, string> > (); args.Peripheral = peripheral; args.RSSI = result.Rssi; handler(this, args); } }