Plugin.Maui.NearbyConnections 0.3.0-preview.1

Suggested Alternatives

Plugin.Maui.NearbyConnectivity

Additional Details

Renamed to Plugin.Maui.NearbyConnectivity. The 0.x previews receive no fixes.

This is a prerelease version of Plugin.Maui.NearbyConnections.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Plugin.Maui.NearbyConnections --version 0.3.0-preview.1
                    
NuGet\Install-Package Plugin.Maui.NearbyConnections -Version 0.3.0-preview.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.Maui.NearbyConnections" Version="0.3.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Plugin.Maui.NearbyConnections" Version="0.3.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Plugin.Maui.NearbyConnections" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Plugin.Maui.NearbyConnections --version 0.3.0-preview.1
                    
#r "nuget: Plugin.Maui.NearbyConnections, 0.3.0-preview.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Plugin.Maui.NearbyConnections@0.3.0-preview.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Plugin.Maui.NearbyConnections&version=0.3.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Plugin.Maui.NearbyConnections&version=0.3.0-preview.1&prerelease
                    
Install as a Cake Tool

Plugin.Maui.NearbyConnections

A .NET MAUI plugin for peer-to-peer (P2P) connectivity with nearby devices by unifying Google's Nearby Connections and Apple's Multipeer Connectivity capabilities.

NuGet Version GitHub License

How it works

Peer-to-peer communication happens in two phases.

Phase 1 — Finding peers. One device advertises its presence; another scans for advertisers. This is a continuous IAsyncEnumerable stream of "device appeared" / "device disappeared" events. Nothing is connected yet — you are learning who is nearby.

Phase 2 — Talking to them. Once you pick a peer and connect (or accept their inbound request), a NearbyConnection is established. That object is itself an async stream of incoming payloads, and exposes SendAsync for the outbound direction.

The tier-1 API (INearbyConnections) exposes these two phases directly as AdvertiseAsync / DiscoverAsync streams. For MAUI app code, the tier-2 services (INearbyAdvertiser / INearbyDiscoverer) stitch both phases into a single EventsAsync stream per role — lifecycle events and payload delivery unified, with current state replayed atomically on subscribe.

Supported Platforms

Platform Minimum Version
Android API 24 (Android 7.0)
iOS iOS 13.0

Dependencies

Dependency Android iOS
Microsoft.Extensions.DependencyInjection.Abstractions ✅ ✅
Microsoft.Maui.Core ✅ ✅
Xamarin.GooglePlayServices.Nearby ✅

Installation

Plugin.Maui.NearbyConnections is available on nuget.org

dotnet add package Plugin.Maui.NearbyConnections

</details>

Getting Started

1. Register the plugin

// MauiProgram.cs
public static MauiApp CreateMauiApp()
    => MauiApp.CreateBuilder()
        .UseMauiApp<App>()
        .AddNearbyConnections()
        .Build();

2. Platform configuration

Android

Add to AndroidManifest.xml:

<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="32"/>
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" android:usesPermissionFlags="neverForLocation" />

iOS

Add to Info.plist:

<key>NSBonjourServices</key>
<array>
  <string>_yourserviceid._tcp</string>
  <string>_yourserviceid._udp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>Used to discover and connect to nearby devices.</string>

The service ID in NSBonjourServices must match NearbyConnectionsOptions.ServiceId (default: app name).

3. Advertise and discover

One device advertises while the other discovers, or both do both simultaneously.

Advertiser side — accept inbound connection requests

using var cts = new CancellationTokenSource();

await foreach (var request in nearbyConnections.AdvertiseAsync(cts.Token))
{
    Console.WriteLine($"Connection request from: {request.RemoteDevice.DisplayName}");

    // Accept to get an established NearbyConnection
    NearbyConnection connection = await request.AcceptAsync(cts.Token);
    Console.WriteLine($"Connected to {connection.RemoteDevice.DisplayName}");

    // Send and receive on this connection (see section 4)
}

To reject a request call request.RejectAsync() instead of AcceptAsync().

Discoverer side — find devices and initiate a connection

using var cts = new CancellationTokenSource();

await foreach (var evt in nearbyConnections.DiscoverAsync(cts.Token))
{
    if (evt.Type == NearbyDeviceEventType.Found)
    {
        Console.WriteLine($"Found: {evt.Device.DisplayName}");

        NearbyConnection connection = await nearbyConnections.ConnectAsync(evt.Device, cts.Token);
        Console.WriteLine($"Connected to {connection.RemoteDevice.DisplayName}");

        // Send and receive on this connection (see section 4)
    }
}

4. Send and receive data

NearbyConnection is obtained from AcceptAsync (advertiser) or ConnectAsync (discoverer).

Send bytes

byte[] data = Encoding.UTF8.GetBytes("Hello!");
await connection.SendAsync(data, cancellationToken);

Send a file

// Pass a file:// URI, or a content:// URI on Android
await connection.SendAsync("file:///path/to/file.bin", cancellationToken: cancellationToken);

Track send progress

var progress = new Progress<NearbyTransferProgress>(p =>
    Console.WriteLine($"Sent {p.BytesTransferred}/{p.TotalBytes} ({p.Fraction:P0})"));

await connection.SendAsync("file:///path/to/file.bin", progress, cancellationToken);

Receive data

await foreach (var payload in connection.ReceiveAsync(cancellationToken))
{
    if (payload is BytesPayload bytes)
    {
        string message = Encoding.UTF8.GetString(bytes.Data);
        Console.WriteLine($"From {connection.RemoteDevice.DisplayName}: {message}");
    }
    else if (payload is FilePayload file)
    {
        Console.WriteLine($"Received file: {file.FileResult.FullPath}");
    }
}

Received files are saved to NearbyConnectionsOptions.ReceivedFilesDirectory (default: FileSystem.AppDataDirectory).

5. Disconnect and clean up

// Disconnect from a specific peer
await connection.DisposeAsync();

// Stop advertising or discovering by canceling the token passed to AdvertiseAsync/DiscoverAsync
cts.Cancel();

// Dispose the plugin when done (e.g. in page OnDisappearing)
await nearbyConnections.DisposeAsync();

Acknowledgements

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-android36.0 is compatible.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-ios26.0 is compatible.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated