@capgo/capacitor-permissions

中文文档
8.2.8发布于 2026/10/15MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4万

Capacitor plugin for checking and requesting app permissions.

原始使用文档
文档目录22 节
  1. ➡️ Get started for free
  2. Features
  3. Use cases
  4. Documentation
  5. Compatibility
  6. Install
  7. iOS setup
  8. Android setup
  9. Web setup
  10. Usage
  11. Example app
  12. API
  13. check(...)
  14. request(...)
  15. checkMultiple(...)
  16. requestMultiple(...)
  17. shouldShowRationale(...)
  18. openSettings(...)
  19. requestPreciseLocation()
  20. getPluginVersion()
  21. Interfaces
  22. Type Aliases

@capgo/capacitor-permissions

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-permissions in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-permissions to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-permissions gives Capacitor apps one TypeScript API to check and request runtime permissions on iOS, Android, and web. Instead of wiring each feature plugin separately or guessing platform-specific status codes, you work with a single set of permission names and normalized states (granted, denied, blocked, limited, unavailable). Native manifests stay lean: the plugin ships without uses-permission entries or forced Info.plist strings, so store review only sees what your app declares.

Features

  • One PermissionName enum for camera, location, notifications, media, contacts, and more across platforms
  • check, request, checkMultiple, and requestMultiple with shared AppPermissionState results
  • Android shouldShowRationale before re-prompting after a denial
  • openSettings for application or notification settings when access is blocked
  • requestPreciseLocation for full accuracy on iOS and ACCESS_FINE_LOCATION on Android
  • Web implementation via the browser Permissions API for supported types
  • Optional scripts/apply-permissions.mjs to add only the Android and iOS declarations you need

Use cases

  • Gate a screen until camera or microphone access is granted
  • Run a startup audit with checkMultiple and show a single onboarding flow for missing permissions
  • Send users to system settings when status is blocked after openSettings
  • Request notification permission before registering push tokens
  • Upgrade from reduced to precise location when a map feature needs it

Documentation

Android emulator showing the camera permission dialog Example app reporting camera permission as granted

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8.*.*v8.*.*✅
v7.*.*v7.*.*On demand
v6.*.*v6.*.*On demand

Policy:

  • New plugins start at version 8.0.0 (Capacitor 8 baseline).
  • Backward compatibility for older Capacitor majors is supported on demand.

Install

npm install @capgo/capacitor-permissions
npx cap sync

With Bun:

bun add @capgo/capacitor-permissions
bunx cap sync

iOS setup

The plugin does not inject usage descriptions into your app. For each PermissionName you call at runtime, add the matching keys to ios/App/App/Info.plist (customize the user-facing strings):

PermissionInfo.plist keys
cameraNSCameraUsageDescription
microphoneNSMicrophoneUsageDescription
photoLibraryNSPhotoLibraryUsageDescription
photoLibraryAddOnlyNSPhotoLibraryAddUsageDescription
contactsNSContactsUsageDescription
calendarNSCalendarsUsageDescription, NSCalendarsFullAccessUsageDescription
remindersNSRemindersUsageDescription, NSRemindersFullAccessUsageDescription
locationWhenInUseNSLocationWhenInUseUsageDescription
locationAlwaysNSLocationWhenInUseUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription
bluetoothNSBluetoothAlwaysUsageDescription
motionNSMotionUsageDescription
speechRecognitionNSSpeechRecognitionUsageDescription, NSMicrophoneUsageDescription
appTrackingTransparencyNSUserTrackingUsageDescription

notifications on iOS uses the system notification permission flow; no extra usage string is required for the API itself. Permissions such as activityRecognition, phone, sms, and Android-style media splits are not applicable on iOS and report unavailable when checked.

You can apply the keys above automatically from the plugin repo:

node node_modules/@capgo/capacitor-permissions/scripts/apply-permissions.mjs \
  --project . \
  --permissions camera,microphone,notifications,locationWhenInUse,photoLibrary

(Point --project at your Capacitor app root, the folder that contains ios/ and android/.)

Android setup

The library AndroidManifest.xml declares no <uses-permission> entries. Add only what your app uses to android/app/src/main/AndroidManifest.xml. The plugin targets minSdk 24 (Android 7.0) unless your project overrides minSdkVersion.

PermissionTypical uses-permission names
cameraandroid.permission.CAMERA
microphone, speechRecognitionandroid.permission.RECORD_AUDIO
photoLibrary, mediaImagesREAD_MEDIA_IMAGES, READ_MEDIA_VISUAL_USER_SELECTED, READ_EXTERNAL_STORAGE (legacy)
photoLibraryAddOnlyWRITE_EXTERNAL_STORAGE (legacy)
contactsREAD_CONTACTS
calendarREAD_CALENDAR, WRITE_CALENDAR
locationWhenInUseACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION
locationAlwaysabove plus ACCESS_BACKGROUND_LOCATION
bluetoothBLUETOOTH, BLUETOOTH_ADMIN, BLUETOOTH_CONNECT, BLUETOOTH_SCAN
motion, activityRecognitionACTIVITY_RECOGNITION
notificationsPOST_NOTIFICATIONS (Android 13+)
phoneREAD_PHONE_STATE
smsREAD_SMS, RECEIVE_SMS
mediaAudioREAD_MEDIA_AUDIO, READ_EXTERNAL_STORAGE
mediaVideoREAD_MEDIA_VIDEO, READ_EXTERNAL_STORAGE

reminders and appTrackingTransparency are not Android runtime permissions in this API and return unavailable.

Use the same apply-permissions.mjs script as on iOS to merge declarations into your app manifest.

Web setup

No manifest changes. Supported permissions use navigator.permissions and related APIs (camera, microphone, notifications, locationWhenInUse; locationAlways maps to foreground geolocation only). Others return unavailable. openSettings is not implemented on web.

Usage

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';
}

Check several permissions before showing an onboarding screen:

const { statuses } = await Permissions.checkMultiple({
  permissions: ['camera', 'microphone', 'notifications'],
});
const missing = Object.entries(statuses).filter(([, s]) => s !== 'granted');

When Android reports denied, show context before requesting again:

const { shouldShow } = await Permissions.shouldShowRationale({ permission: 'camera' });
if (shouldShow) {
  // Show your own explanation UI, then:
  await Permissions.request({ permission: 'camera' });
}

If status is blocked, send the user to settings:

await Permissions.openSettings({ type: 'application' });

Example app

The example-app/ project exercises every PermissionName. Apply declarations, sync native projects, then:

cd example-app
bun install
bun run start

API

Cross-platform permissions API for Capacitor apps.

check(...)

check(options: PermissionOptions) => Promise<PermissionStatusResult>

Check the current status of one permission without prompting the user.

ParamType
optionsPermissionOptions

Returns: Promise<PermissionStatusResult>

Since: 8.0.0


request(...)

request(options: PermissionOptions) => Promise<PermissionStatusResult>

Request one permission from the user. On Android, shows the system dialog when needed. On iOS, triggers the platform authorization flow for the mapped capability.

ParamType
optionsPermissionOptions

Returns: Promise<PermissionStatusResult>

Since: 8.0.0


checkMultiple(...)

checkMultiple(options: MultiplePermissionOptions) => Promise<MultiplePermissionStatusResult>

Check several permissions without prompting.

ParamType
optionsMultiplePermissionOptions

Returns: Promise<MultiplePermissionStatusResult>

Since: 8.0.0


requestMultiple(...)

requestMultiple(options: MultiplePermissionOptions) => Promise<MultiplePermissionStatusResult>

Request several permissions sequentially so dialogs are not shown on top of each other.

ParamType
optionsMultiplePermissionOptions

Returns: Promise<MultiplePermissionStatusResult>

Since: 8.0.0


shouldShowRationale(...)

shouldShowRationale(options: PermissionOptions) => Promise<ShouldShowRationaleResult>

Whether Android should show a rationale before requesting again. Returns { shouldShow: false } on iOS and web.

ParamType
optionsPermissionOptions

Returns: Promise<ShouldShowRationaleResult>

Since: 8.0.0


openSettings(...)

openSettings(options?: OpenSettingsOptions | undefined) => Promise<void>

Open the application or notification settings screen. Rejects on web with UNIMPLEMENTED.

ParamType
optionsOpenSettingsOptions

Since: 8.0.0


requestPreciseLocation()

requestPreciseLocation() => Promise<PermissionStatusResult>

Ask for precise location. On iOS, requests temporary full accuracy when already authorized when-in-use. On Android, requests ACCESS_FINE_LOCATION. On web, returns the geolocation permission status after prompting when possible.

Returns: Promise<PermissionStatusResult>

Since: 8.0.0


getPluginVersion()

getPluginVersion() => Promise<PluginVersionResult>

Returns the platform implementation version marker.

Returns: Promise<PluginVersionResult>

Since: 8.0.0


Interfaces

PermissionStatusResult

Result for a single permission status.

PropTypeDescriptionSince
statusAppPermissionStateCurrent status for the requested permission.8.0.0

PermissionOptions

Options for checking or requesting a single permission.

PropTypeDescriptionSince
permissionPermissionNameLogical permission to evaluate or request.8.0.0

MultiplePermissionStatusResult

Result for several permission statuses.

PropTypeDescriptionSince
statusesRecord<string, AppPermissionState>Map of permission name to status. Keys match the names passed in permissions.8.0.0

MultiplePermissionOptions

Options for checking or requesting several permissions.

PropTypeDescriptionSince
permissionsPermissionName[]Permissions to evaluate in order. On requestMultiple, each permission is requested one after another.8.0.0

ShouldShowRationaleResult

Result for Android rationale checks.

PropTypeDescriptionSince
shouldShowbooleanTrue only when Android would show a rationale dialog before requesting again. Always false on iOS and web.8.0.0

OpenSettingsOptions

Options for opening system settings.

PropTypeDescriptionDefaultSince
typeSettingsTypeWhich settings screen to open.'application'8.0.0

PluginVersionResult

Plugin version payload.

PropTypeDescriptionSince
versionstringVersion identifier returned by the platform implementation (native on mobile, web in browsers).8.0.0

Type Aliases

AppPermissionState

Normalized permission status returned by every platform implementation.

  • granted: the user allowed full access.
  • denied: the user has not granted access yet, or Android can show a rationale.
  • blocked: the user denied access and the app cannot prompt again without settings.
  • limited: partial access (for example iOS limited photo library or reduced location accuracy).
  • unavailable: the permission is not supported on this platform or not declared in the app manifest.

'granted' | 'denied' | 'blocked' | 'limited' | 'unavailable'

PermissionName

Logical permission identifiers shared across iOS, Android, and web.

Android-only names include activityRecognition, phone, sms, mediaAudio, mediaImages, and mediaVideo. iOS-only names include reminders and appTrackingTransparency. Web supports a subset via browser APIs (camera, microphone, notifications, locationWhenInUse). On web, locationAlways is an alias of foreground geolocation only; browsers do not expose background location permission.

'camera' | 'microphone' | 'photoLibrary' | 'photoLibraryAddOnly' | 'contacts' | 'calendar' | 'reminders' | 'locationWhenInUse' | 'locationAlways' | 'bluetooth' | 'motion' | 'notifications' | 'speechRecognition' | 'appTrackingTransparency' | 'activityRecognition' | 'phone' | 'sms' | 'mediaAudio' | 'mediaImages' | 'mediaVideo'

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

SettingsType

Settings screen type for openSettings.

'application' | 'notifications'

版本与发布记录

@capgo/capacitor-permissions 共发布 9 个版本,首次发布于 2026/10/01;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.2.8latest2026/10/1525 天前
8.2.72026/10/1327 天前
8.2.62026/10/091 个月前
8.2.52026/10/081 个月前
8.2.42026/10/081 个月前
8.2.32026/10/011 个月前

关于 @capgo/capacitor-permissions 的常见问题

@capgo/capacitor-permissions 是什么?

Capacitor plugin for checking and requesting app permissions.

如何安装 @capgo/capacitor-permissions?

在项目目录运行 npm install @capgo/capacitor-permissions,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-permissions 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-permissions 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-permissions 可以商用吗?

@capgo/capacitor-permissions 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-permissions 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-permissions 在 2026/10/09 – 2026/11/07 这 30 天内被下载 39,796 次,日均约 1,327 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-permissions 还在维护吗?

最新版本 8.2.8 发布于 2026/10/15(25 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/10/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。