更新记录
2.0.6(2025-03-12) 下载此版本
文档更新
2.0.5(2025-02-21) 下载此版本
1
2.0.4(2025-02-21) 下载此版本
优化
查看更多平台兼容性
Vue2 | Vue3 |
---|---|
√ | √ |
App | 快应用 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|
app-vue | × | × | × | × | × | × |
钉钉小程序 | 快手小程序 | 飞书小程序 | 京东小程序 | 鸿蒙元服务 |
---|---|---|---|---|
× | × | × | × | × |
H5-Safari | Android Browser | 微信浏览器(Android) | QQ浏览器(Android) | Chrome | IE | Edge | Firefox | PC-Safari |
---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | × | × | × |
建议使用本插件升级版本(根据官方的新接口实现更完善) 点击跳转
用法说明,可选两种使用方式
注意:部分厂商的部分系统版本,可能会出现重复申请权限的情况(不一定影响审核上架,因为审核的手机系统版本有多种) 如出现上述问题导致无法通过审核请使用(方式二)自行处理或使用其他插件
方式一,在main.js引入(全局处理,不破坏原本业务逻辑)
import { addPermisionInterceptor, removePermisionInterceptor } from '@/uni_modules/x-perm-apply-instr/js_sdk/index.js'
addPermisionInterceptor('chooseImage', '为了修改个人头像和发布信息图片视频等, 我们需要申请您设备的相机和存储权限')
addPermisionInterceptor('chooseVideo', '为了发布信息图片视频等, 我们需要申请您设备的相机和存储权限')
addPermisionInterceptor('saveImageToPhotosAlbum', '为了保存推广海报到手机相册, 我们需要申请您设备的存储权限')
addPermisionInterceptor('getLocation', '为了根据您的位置展示信息, 我们需要申请您设备的位置权限')
addPermisionInterceptor('makePhoneCall', '为了联系客服/用户/咨询等, 我们需要申请您设备的拨打电话权限')
addPermisionInterceptor('getRecorderManager', '为了使用语言消息功能等, 我们需要申请您设备的麦克风权限')
addPermisionInterceptor('startLocationUpdate', '为了根据您的位置展示信息, 我们需要申请您设备的位置权限')
addPermisionInterceptor('scanCode', '为了识别二维码信息, 我们需要申请您设备的相机权限')
addPermisionInterceptor 添加 uniApi 调用拦截
位置 | 类型 | 描述 | 可选值 |
---|---|---|---|
0 | String | 要拦截的 uniApi 名称 | scanCode、chooseImage、chooseVideo、saveImageToPhotosAlbum、saveVideoToPhotosAlbum、getLocation、startLocationUpdate、makePhoneCall、getRecorderManager、startBluetoothDevicesDiscovery |
1 | String | 申请权限说明信息 | 自定义文本 |
2 | Boolean | 只询问一次, 用户不同意申请或拒绝权限将无法使用 uniApi, 如果要继续使用 Api 先用 removePermisionInterceptor 函数移除拦截再调用 Api | true, false |
removePermisionInterceptor 移除 uniApi 调用拦截
位置 | 类型 | 描述 | 可选值 |
---|---|---|---|
0 | String | 要移除拦截的 uniApi 名称 | 同上 |
注意, 如果需要拦截 getRecorderManager , 在使用时不要直接在 script 下初始化, 会导致拦截失败, 请在 onLoad 或 onReady 中调用
<script>
// 错误写法
const recorderManager = uni.getRecorderManager();
// 正确写法
let recorderManager = null
export default {
onLoad() {
recorderManager = uni.getRecorderManager();
}
}
</script>
方式二,手动控制权限说明弹窗(自行在需要使用权限的功能处增加显示/关闭逻辑)
import { popup } from '@/uni_modules/x-perm-apply-instr/js_sdk/native_popup.js'
// 显示
popup.show({
title: '权限申请说明',
content: '为了xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
})
// 关闭
popup.close()