快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-permissions`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/permissions/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
“安装”章节你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-permissions` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-permissionsbunx cap sync导入
“导入”章节import { Permissions } from '@capgo/capacitor-permissions';快速入门
章节标题为“快速入门”import { Permissions } from '@capgo/capacitor-permissions';
const { status } = await Permissions.check({ permission: 'camera' });示例:request
标题为“示例:request”的部分import { Permissions } from '@capgo/capacitor-permissions';
const { status } = await Permissions.request({ permission: 'notifications' });示例:checkMultiple
标题为“示例:checkMultiple”的部分import { Permissions } from '@capgo/capacitor-permissions';
const { statuses } = await Permissions.checkMultiple({ permissions: ['camera', 'microphone'],});常见坑点
章节标题为“常见陷阱”- 原生同步:运行
bunx cap sync在插件升级后。 - 唯一可信来源:信任
src/definitions.ts在 GitHub 仓库中。
平台设置
标题为“平台设置”的章节- iOS 配置 用于 Info.plist 的使用说明字符串
PermissionName. - Android 配置 来实现
uses-permission条目和 minSdk 24。
使用情况
标题为“用法”的章节import { Permissions } from '@capgo/capacitor-permissions';
export async function ensureCamera(): Promise<boolean> { const { status } = await Permissions.check({ permission: 'camera' }); if (status === 'granted') return true; const { status: afterRequest } = await Permissions.request({ permission: 'camera' }); return afterRequest === 'granted';}当状态为 blocked,引导用户前往设置:
await Permissions.openSettings({ type: 'application' });