Class NearbyPermission
- Namespace
- Plugin.Maui.NearbyConnectivity
- Assembly
- Plugin.Maui.NearbyConnectivity.dll
The runtime permissions nearby connectivity needs on the current platform.
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "The 'Permission' suffix is the .NET MAUI convention for a Permissions.BasePlatformPermission subclass — it is how Permissions.RequestAsync<T>() reads at the call site, and every first-party permission type (Permissions.Bluetooth, Permissions.LocationWhenInUse) sits under that same API. Renaming would make this type read as something other than what it is.")]
public sealed class NearbyPermission : Permissions.BasePlatformPermission
- Inheritance
-
NearbyPermission
- Inherited Members
Remarks
Use it the way every other .NET MAUI permission is used:
var status = await Permissions.RequestAsync<NearbyPermission>();
if (status is not PermissionStatus.Granted)
{
// Direct the user to system settings.
return;
}
await nearby.Discoverer.StartAsync(cancellationToken);
This type resolves the right set for the running platform and OS version. On Android that set
differs by API level: location before 31, the granular BLUETOOTH_* permissions from 31,
and NEARBY_WIFI_DEVICES from 33. Requesting the wrong set fails silently, with
advertising and discovery starting and never seeing anything.
On iOS there is no runtime permission to request, so both members report
Granted and shared code can call them unconditionally.
MultipeerConnectivity is gated by the NSLocalNetworkUsageDescription and
NSBonjourServices keys in Info.plist instead. iOS shows its Local Network prompt
on first use. If the person denies it, discovery finds nothing, no error is reported, and this
type still reports Granted.
StartAsync(CancellationToken) reports a missing permission rather than prompting. Requesting is the application's decision.
Methods
CheckStatusAsync()
Reports Granted on targets with no nearby connectivity support, so shared code can call it unconditionally.
public override Task<PermissionStatus> CheckStatusAsync()
Returns
- Task<PermissionStatus>
A task whose result is always Granted.
Remarks
A permission is not what is missing on an unsupported target. The platform is. That is reported by CheckAvailabilityAsync(CancellationToken) as Unsupported, which is where a caller should branch.
RequestAsync()
Reports Granted on targets with no nearby connectivity support, so shared code can call it unconditionally.
public override Task<PermissionStatus> RequestAsync()
Returns
- Task<PermissionStatus>
A task whose result is always Granted.
Remarks
A permission is not what is missing on an unsupported target. The platform is. That is reported by CheckAvailabilityAsync(CancellationToken) as Unsupported, which is where a caller should branch.