Skip to content

BLE Manager

IBleManager is the main entry point for scanning and managing BLE peripherals. Inject it via dependency injection.

Before scanning, request the necessary permissions. This also checks the Bluetooth adapter state.

IBleManager bleManager; // injected
var access = await bleManager.RequestAccessAsync();
if (access != AccessState.Available)
{
// Bluetooth is not available - show a message
}

Scanning returns an IObservable<ScanResult> that emits each time a peripheral advertisement is detected.

var scanSub = bleManager
.Scan()
.Subscribe(scanResult =>
{
var peripheral = scanResult.Peripheral;
var name = peripheral.Name;
var rssi = scanResult.Rssi;
var serviceUuids = scanResult.AdvertisementData.ServiceUuids;
});
// To stop scanning
scanSub.Dispose();
// or
bleManager.StopScan();

Filtering by service UUID is more efficient and is required for background scanning on iOS.

var scanSub = bleManager
.Scan(new ScanConfig("Your-Service-UUID"))
.Subscribe(scanResult =>
{
// Only peripherals advertising this service UUID
});
// Scan until a peripheral with a specific name is found
var peripheral = await bleManager
.ScanUntilPeripheralFound("MyDevice")
.ToTask();
// Scan until the first peripheral with a service UUID is found
var peripheral = await bleManager
.ScanUntilFirstPeripheralFound("Your-Service-UUID")
.ToTask();
// Get only unique peripherals (no duplicate emissions)
bleManager
.ScanForUniquePeripherals()
.Subscribe(peripheral => { });
var connected = bleManager.GetConnectedPeripherals();
foreach (var peripheral in connected)
{
Console.WriteLine($"{peripheral.Name} - {peripheral.Uuid}");
}

If you have a peripheral UUID from a previous scan, you can retrieve it without scanning.

var peripheral = bleManager.GetKnownPeripheral("peripheral-uuid");
if (peripheral != null)
{
peripheral.Connect();
}

The managed scanner maintains an observable collection of scan results, handling duplicates, UI thread marshaling, and automatic cleanup of stale results.

var scanner = bleManager.CreateManagedScanner();
// Start scanning
await scanner.Start(
scanConfig: new ScanConfig("Your-Service-UUID"),
bufferTime: TimeSpan.FromSeconds(1),
clearTime: TimeSpan.FromSeconds(10) // Remove peripherals not seen in 10 seconds
);
// Bind to the collection (great for MAUI ListView/CollectionView)
var peripherals = scanner.Peripherals; // INotifyReadOnlyCollection<ManagedScanResult>
// Each ManagedScanResult has:
// - Peripheral (IPeripheral)
// - Name, Uuid, Rssi, IsConnected
// - ManufacturerData, ServiceUuids, LastSeen
// Watch for changes
scanner.WhenScan().Subscribe(change =>
{
// change.Action: Add, Update, Remove, Clear
// change.ScanResult: the affected ManagedScanResult
});
// Stop scanning
scanner.Stop();
scanner.Dispose();