maui-permissions
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "maui-permissions":https://skillpi.com/zh/skills/deepskill-9fdcefcf4ffbb6ec8988c6322d09d22782530a0546f16900e9688028f475f4d9。安装前核对上游来源和版本:https://github.com/davidortinau/maui-skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
.NET MAUI 运行时权限指南,说明如何检查与请求权限、处理 PermissionStatus、通过 BasePlatformPermission 实现自定义权限、在平台清单/Info.plist 中声明权限,以及支持依赖注入的服务模式。适用于请求权限、检查权限、PermissionStatus、运行时权限、BasePlatformPermission、自定义权限、Android 清单和 Info.plist 权限声明及权限被拒绝的处理。非地理位置、相机/照片或通知权限的专门指南。
介绍来源: third_party · davidortinau · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
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
- [ ]
CheckStatusAsynccalled before everyRequestAsync - [ ] No permission calls in constructors — use
OnAppearingor commands - [ ] All
PermissionStatusvalues handled (Denied,Restricted,Limited) - [ ] Android:
ShouldShowRationaleshown before re-requesting - [ ] iOS: Settings navigation provided for denied permissions
- [ ] Android API 33+: using
Photos/Mediainstead ofStorageRead/StorageWrite - [ ] Manifest/plist declarations match runtime permission requests
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 高价值/高频刚需:解决.NET MAUI跨平台运行时权限的核心痛点
- 明确界定适用范围,避免功能重叠
- 覆盖iOS/Android/Windows三大平台的特有问题
亮点
- 触发词精准完整,覆盖多种变体
- 边界清晰,明确列出适用与不适用场景
- 避免与其他Skill(maui-geolocation等)重叠
亮点
- Phase/步骤清晰(反模式→平台陷阱→最佳实践→检查清单)
- 包含完整端到端代码示例和可复用模式
- frontmatter完整,文档长度适中
亮点
- 工具来源明确(.NET MAUI官方Permissions API)
- 覆盖主要异常状态(Denied/Restricted/Limited)
- 平台特定问题均有可靠解决方案
- 提供可复用的CheckAndRequestPermissionAsync最佳实践模式
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。