Skip to content

x-permission-s 权限

跨端权限查询与申请。业务只用 locationcamera 这类稳定字段,不要直接写各端原生权限名。

success 只表示流程走完,不代表已全部授权。是否可用看 result.granted,逐项看 result.permissions

兼容性

HarmonyIOSAndroidWEB小程序
支持支持支持支持支持

调用

ts
import { getPermissions, checkPermissions, requestPermissions, openPermissionSettings } from "@/uni_modules/x-permission-s"

const xPermissions = getPermissions()
const list = [
  xPermissions.location,
  xPermissions.camera,
  xPermissions.microphone,
  xPermissions.photos,
  xPermissions.notification
] as string[]

checkPermissions({
  permissions: list,
  success: (result) => {
    console.log(result.granted, result.permissions)
  }
})

requestPermissions({
  permissions: list,
  autoOpenSettings: true,
  continueAfterSettings: true,
  success: (result) => {
    console.log(result.granted)
  }
})

openPermissionSettings({
  permission: xPermissions.location
})

方法

名称需要说明
getPermissions返回稳定字段对象,如 xPermissions.location
checkPermissionspermissions: string[],可选回调只查询,不弹授权框
requestPermissionspermissions,可选 autoOpenSettingscontinueAfterSettings申请权限;success 只表示流程走完,是否授权看 result.granted
openPermissionSettings可选 permission打开应用设置,或某项权限的系统入口

参数

稳定字段:locationlocationAlwayscameramicrophonephotosphotosAddOnlycontactscalendarnotificationbluetoothmotionphonesmsstorage

checkPermissions / requestPermissions

字段说明默认
permissions稳定字段数组必填
autoOpenSettings仅申请:永久拒绝或服务关闭时是否打开设置false
continueAfterSettings仅申请:从设置返回后是否再查一次true
success流程结束-
fail失败-
complete结束-

XPermissionResultgranted / allGranteddenied / hasDeniedpermissionsdeniedPermissionsgrantedMapdeniedMap

单项 statusgranted / denied / notDetermined / restricted / serviceDisabled / limited / unsupported。当前端没有对应能力时是 unsupported,不会当成用户拒绝。

错误码:1001 系统错误,1002 权限参数为空,1003 含不支持的标识,1004 打不开设置,1005 已有请求进行中。

平台差异

  1. Web 仅 location / camera / microphone / notification,不能打开系统设置。
  2. 微信仅 location / camera / microphone / photosAddOnly,须在 manifest 声明对应 scope。
  3. 鸿蒙仅部分字段有等价能力,其余为 unsupported
  4. Android 13+ 的 storageunsupported

版本

版权归https://xui.tmui.design你不得修改及二次开发,仅供TMUI4会员商用使用。不得转给非VIP会员使用,一经查实数倍赔偿,并追究法律责任。

更新日志

1.0.0(2026-07-31)

  • 首次发布:多权限查询、请求、详细结果与设置页跳转。
最近更新