maui-permissions

.NET MAUI runtime permissions guide explaining how to check and request permissions, handle PermissionStatus, implement custom permissions via BasePlatformPermission, declare permissions in platform manifests/Info.plist, and use DI-friendly service patterns. Suitable for requesting permissions, checking permissions, PermissionStatus, runtime permissions, BasePlatformPermission, custom permissions, Android manifest and Info.plist declarations, and handling denied permissions. Not a specialized guide for geolocation, camera/photo, or notification permissions.

Last repository push
GitHub Stars
181
Forks
21
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "maui-permissions" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-9fdcefcf4ffbb6ec8988c6322d09d22782530a0546f16900e9688028f475f4d9. Verify the upstream source and version against https://github.com/davidortinau/maui-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

.NET MAUI runtime permissions guide explaining how to check and request permissions, handle PermissionStatus, implement custom permissions via BasePlatformPermission, declare permissions in platform manifests/Info.plist, and use DI-friendly service patterns. Suitable for requesting permissions, checking permissions, PermissionStatus, runtime permissions, BasePlatformPermission, custom permissions, Android manifest and Info.plist declarations, and handling denied permissions. Not a specialized guide for geolocation, camera/photo, or notification permissions.

0 Downloads

Introduction source: third_party · davidortinau · 0.0.1 Reference

SkillPi interpretation

Tasks
// ✅ Check first — avoids unnecessary prompts var status = await Permissions.CheckStatusAsync<Permissions.Camera>(); if (status != PermissionStatus.Granted) status = await Permissions.RequestAsync<Permissions.Camera>(); ```
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: maui-permissions
description: >
  .NET MAUI runtime permissions guidance — checking and requesting permissions,
  PermissionStatus handling, custom permissions via BasePlatformPermission,
  platform-specific manifest/plist declarations, and DI-friendly service patterns.
  USE FOR: "request permission", "check permission", "PermissionStatus", "runtime permission",
  "BasePlatformPermission", "custom permission", "Android manifest permission",
  "Info.plist permission", "permission denied handling".
  DO NOT USE FOR: geolocation-specific permissions (use maui-geolocation),
  camera/photo permissions (use maui-media-picker), or notification permissions (use maui-local-notifications).

.NET MAUI Permissions — Gotchas & Best Practices

Critical Anti-Patterns

1. Requesting without checking first

// ❌ Shows prompt even if already granted
var status = await Permissions.RequestAsync<Permissions.Camera>();

// ✅ Check first — avoids unnecessary prompts
var status = await Permissions.CheckStatusAsync<Permissions.Camera>();
if (status != PermissionStatus.Granted)
    status = await Permissions.RequestAsync<Permissions.Camera>();

2. Calling permissions in a constructor

Permission APIs are async and require a UI context. Constructors can't await.

// ❌ Blocks the UI thread or throws
public MyViewModel()
{
    var status = Permissions.RequestAsync<Permissions.Camera>().Result;
}

// ✅ Use OnAppearing, a command, or async initialization
protected override async void OnAppearing()
{
    await CheckAndRequestPermissionAsync<Permissions.Camera>();
}

3. Ignoring Denied and Restricted status

// ❌ Only checks for Granted — misses edge cases
if (status == PermissionStatus.Granted) { /* proceed */ }

// ✅ Handle all relevant statuses
switch (status)
{
    case PermissionStatus.Granted: /* proceed */ break;
    case PermissionStatus.Limited: /* iOS partial access */ break;
    case PermissionStatus.Denied:
    case PermissionStatus.Restricted:
        await ShowSettingsPromptAsync(); break;
}

Platform Pitfalls

⚠️ iOS: One-shot permission dialog

iOS shows the system permission dialog only once per permission, ever. After denial, RequestAsync returns Denied immediately without showing UI. You must guide the user to Settings → App → Permission.

⚠️ Android: ShouldShowRationale timing

ShouldShowRationale returns true only after a prior denial (but not after "Don't ask again"). Use it to show explanatory UI before re-requesting:

if (Permissions.ShouldShowRationale<Permissions.Camera>())
{
    await Shell.Current.DisplayAlert("Permission needed",
        "Camera access is required to scan barcodes.", "OK");
}
status = await Permissions.RequestAsync<Permissions.Camera>();

⚠️ Android API 33+: StorageRead/StorageWrite are dead

On Android 13+, StorageRead and StorageWrite always return Granted (scoped storage makes them meaningless). Use granular media permissions instead:

// ❌ Always returns Granted on API 33+ — gives false confidence
await Permissions.RequestAsync<Permissions.StorageRead>();

// ✅ Use the specific media permission
await Permissions.RequestAsync<Permissions.Photos>();       // photo access
await Permissions.RequestAsync<Permissions.Media>();         // audio/video

⚠️ Windows: Most permissions always return Granted

Windows doesn't have runtime permission dialogs for most features. Declare capabilities in Package.appxmanifest instead.

Always-Check-Before-Request Pattern

The recommended pattern handles iOS one-shot and Android rationale:

public async Task<PermissionStatus> CheckAndRequestPermissionAsync<T>()
    where T : Permissions.BasePermission, new()
{
    var status = await Permissions.CheckStatusAsync<T>();
    if (status == PermissionStatus.Granted)
        return status;

    if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
        return status; // iOS won't show dialog again

    if (Permissions.ShouldShowRationale<T>())
    {
        await Shell.Current.DisplayAlert("Permission needed",
            "This feature requires the requested permission.", "OK");
    }

    return await Permissions.RequestAsync<T>();
}

Checklist

  • [ ] CheckStatusAsync called before every RequestAsync
  • [ ] No permission calls in constructors — use OnAppearing or commands
  • [ ] All PermissionStatus values handled (Denied, Restricted, Limited)
  • [ ] Android: ShouldShowRationale shown before re-requesting
  • [ ] iOS: Settings navigation provided for denied permissions
  • [ ] Android API 33+: using Photos/Media instead of StorageRead/StorageWrite
  • [ ] Manifest/plist declarations match runtime permission requests

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value95/100

Highlights

  • 高价值/高频刚需:解决.NET MAUI跨平台运行时权限的核心痛点
  • 明确界定适用范围,避免功能重叠
  • 覆盖iOS/Android/Windows三大平台的特有问题
Trigger Precision95/100

Highlights

  • 触发词精准完整,覆盖多种变体
  • 边界清晰,明确列出适用与不适用场景
  • 避免与其他Skill(maui-geolocation等)重叠
Structure and Standards95/100

Highlights

  • Phase/步骤清晰(反模式→平台陷阱→最佳实践→检查清单)
  • 包含完整端到端代码示例和可复用模式
  • frontmatter完整,文档长度适中
Execution Reliability95/100

Highlights

  • 工具来源明确(.NET MAUI官方Permissions API)
  • 覆盖主要异常状态(Denied/Restricted/Limited)
  • 平台特定问题均有可靠解决方案
  • 提供可复用的CheckAndRequestPermissionAsync最佳实践模式
Evidence Verifiability (mean of the first four)95/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.