# react-native-systempermissions **Repository Path**: duantianqi/react-native-systempermissions ## Basic Information - **Project Name**: react-native-systempermissions - **Description**: react-native-systempermissions 设备权限获取 - **Primary Language**: JavaScript - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-02-03 - **Last Updated**: 2022-12-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 远薪系统权限管理组件 #### 总体介绍 系统权限管理组件源码路径为http://yxsource.sinooceanland.net/platform/react-native-systempermissions.git ​ 该组件提供如下平台权限的检测与请求开通管理 | 名称 | KEY | IOS | Android | | --------- | ----------------- | ---- | ------- | | GPS 位置 | location | ✔️ | ✔️ | | 照像机 | camera | ✔️ | ✔️ | | 语音 | microphone | ✔️ | ✔️ | | 照片 | photo | ✔️ | ✔️ | | 联系人 | contacts | ✔️ | ✔️ | | 日历数据库(事件) | event | ✔️ | ✔️ | | 蓝牙 | bluetooth | ✔️ | ✔️ | | 日历数据库(提醒) | reminder | ✔️ | ❌ | | 通知 | notification | ✔️ | ❌ | | 后台刷新 | backgroundRefresh | ✔️ | ❌ | | 存储 | storage | ✔️ | ❌ | | | | | | #### 方法说明 | 方法 | 参数 | 说明 | | ------------------------ | ------- | ---- | | getPermissionStatus | type | | | requestPermission | type | | | checkMultiplePermissions | [types] | | | getPermissionTypes | none | | | openSettings | none | | | canOpenSettings | none | | #### 方法返回结果 | 返回值 | 说明 | | ------------ | ---------------------------------------- | | authorized | 已授权此权限 | | denied | 用户至少拒绝一次。 在iOS上不会再次提示用户, Android用户可以多次提交 | | restricted | (仅限iOS)用户无法授予此权限,因为它不受设备支持或者已被家长控制权阻止。 | | undetermined | 尚未通过权限对话框提示 | #### 使用方法 获取权限状态 ``` import { PermissionsManager } from 'react-native-systempermissions'; //获取权限状态 PermissionsManager.getPermissionStatus('photo') .then(response => { // 'authorized', 'denied', 'restricted', 'undetermined' this.setState({ photoPermission: response }) }); //获取带参数权限状态 PermissionsManager.getPermissionStatus('location', 'always') .then(response => { this.setState({ locationPermission: response }) }) //请求打开权限 PermissionsManager.requestPermission('photo') .then(response => { // 'authorized', 'denied', 'restricted', 'undetermined' this.setState({ photoPermission: response }) }); //获取带参数权限状态 PermissionsManager.requestPermission('location', 'always') .then(response => { this.setState({ locationPermission: response }) }) //获取通知的权限 PermissionsManager.requestPermission('notification', ['alert', 'badge']) .then(response => { this.setState({ notificationPermission: response }) }) //一次请求多个权限 Permissions.checkMultiplePermissions(['camera', 'photo']) .then(response => { //response is an object mapping type to permission this.setState({ cameraPermission: response.camera, photoPermission: response.photo, }) }); //是否可以打开权限设置页 PermissionsManager.canOpenSettings(); //打开权限设置页 PermissionsManager.openSettings(); ``` android配置注意 1.在manifest.xml下要有如下权限 ``` ``` 2.在manifest.xml下,和build.gradle中targetSdkVersion必须在23以上,23以下默认权限自动授权(targetSdkVersion=24)