Registry / auth-security / react-native-permissions

react-native-permissions

JSON →
library5.5.1jsnpmunverified

react-native-permissions provides a unified, cross-platform API for managing user permissions on iOS, Android, and Windows within React Native applications. It abstracts away the platform-specific nuances of checking and requesting permissions like camera, location, and notifications, offering a consistent interface. The current stable version is 5.5.1. The library follows the React Native release support policy, supporting the latest version and the two previous minor series, indicating a regular update cadence aligned with React Native itself. A key differentiator is its modular iOS setup, where developers explicitly enable only the permissions they need via a `Podfile` script, reducing the app's binary size and simplifying configuration, alongside robust TypeScript support and handling of nuances like Android's one-time permissions. It supports Windows builds 18362 and later, extending its reach beyond mobile.

npm install react-native-permissions
INSTALL
IMPORT
SIG · REACT-NATIVE-PERMI
R
react-native-permissions
auth-securityjavascriptv5.5.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

request
import { request } from 'react-native-permissions';
import request from 'react-native-permissions';
This is a named export, not a default export. Incorrectly importing as a default will result in an undefined function.
check
import { check } from 'react-native-permissions';
const { check } = require('react-native-permissions');
While CommonJS `require` might work in some setups, the library is primarily designed for ES Modules. For optimal bundle size and modern tooling, use `import`.
PERMISSIONS
import { PERMISSIONS } from 'react-native-permissions';
Contains platform-specific permission constants (e.g., PERMISSIONS.ANDROID.CAMERA, PERMISSIONS.IOS.LOCATION_WHEN_IN_USE).
RESULTS
import { RESULTS } from 'react-native-permissions';
Contains constants for permission statuses (e.g., RESULTS.GRANTED, RESULTS.DENIED, RESULTS.BLOCKED).
Platform
import { Platform } from 'react-native';
Often used in conjunction with this library to select platform-specific permissions.

Demonstrates checking and requesting camera permission, handling different statuses across iOS and Android.

import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions'; import { Platform, Alert } from 'react-native'; const getCameraPermission = async () => { let permission; if (Platform.OS === 'ios') { permission = PERMISSIONS.IOS.CAMERA; } else if (Platform.OS === 'android') { permission = PERMISSIONS.ANDROID.CAMERA; } else { Alert.alert('Unsupported platform'); return; } try { let result = await check(permission); if (result === RESULTS.DENIED) { result = await request(permission); } if (result === RESULTS.GRANTED) { Alert.alert('Camera permission granted!'); } else if (result === RESULTS.BLOCKED) { Alert.alert('Camera permission blocked', 'Please go to settings to enable camera.'); } else { Alert.alert('Camera permission status: ' + result); } } catch (error) { console.error('Permission check failed', error); Alert.alert('Error requesting permission'); } }; // Call this function from a component or an event handler // getCameraPermission();
Debug
Known issues
breakingStarting with v5.5.0, the package utilizes the `package.json` `exports` property for module resolution. This requires bundlers to be configured correctly.
fix
Ensure your `tsconfig.json` (for TypeScript projects) has `"moduleResolution": "bundler"` configured, or update your bundler settings if not using TypeScript, to correctly resolve module imports.
affects: >=5.5.0
gotchaiOS permissions require explicit declaration in the `Podfile` and corresponding usage descriptions in `Info.plist`. Failing to do so will result in runtime crashes or permissions not being available.
fix
In your `Podfile`, use `node_require('react-native-permissions/scripts/setup.rb')` and call `setup_permissions([])` with the desired permissions. Then, add privacy keys (e.g., `NSCameraUsageDescription`) to your `Info.plist` with a user-facing reason string.
affects: >=1.0.0
gotchaOn Android, `check` might return `UNAVAILABLE` for unsupported permissions instead of `DENIED`. This was addressed in v5.4.2.
fix
Upgrade to `react-native-permissions` v5.4.2 or higher to ensure `check` returns `DENIED` when appropriate for unsupported permissions, leading to more consistent logic flow.
affects: <5.4.2
gotchaWhen requesting location permissions on iOS 14 and above, granular `LocationAccuracy` (`LocationWhenInUse` or `LocationAlways`) can be requested. Using `CLLocationManager` directly for authorization status on older iOS versions might lead to incorrect behavior.
fix
Upgrade to `react-native-permissions` v5.4.3 or higher which correctly uses `CLLocationManager` instance `authorizationStatus` on iOS >= 14, improving accuracy and compatibility.
affects: <5.4.3
gotchaMissing privacy usage descriptions in `Info.plist` (iOS) or `AndroidManifest.xml` (Android) for requested permissions will cause the app to crash or permissions to be silently denied by the OS.
fix
Always add the required `Privacy - [Permission Type] Usage Description` keys to your `Info.plist` for iOS, and appropriate `<uses-permission>` tags with reasonable descriptions to your `AndroidManifest.xml` for Android. These descriptions explain to the user why the app needs the permission.
affects: >=1.0.0
Errors
Common errors & fixes
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NS[PermissionType]UsageDescription key with a string value explaining to the user how the app uses this data.
Missing `Info.plist` entry for a requested iOS permission.
fix
Add the corresponding `NS[PermissionType]UsageDescription` key (e.g., `NSCameraUsageDescription`) and a descriptive string value to your `Info.plist` file in your iOS project.
`_NativePermissions.check` is null or not an object.
Native module not linked correctly, or permissions not configured in Podfile for iOS.
fix
For iOS, ensure `setup_permissions()` is called in your `Podfile` with the required permissions and run `pod install`. For Android, verify auto-linking or manual linking steps if necessary. Clean build caches and rebuild the app.
Error: `TypeError: null is not an object (evaluating '_NativePermissions.request')`
Similar to the `check` error, indicates the native module isn't properly initialized or linked for the target platform.
fix
Check your `Podfile` for `react-native-permissions/scripts/setup.rb` and `setup_permissions()`. Ensure `pod install` has been run. For Android, verify `MainApplication.java` has `new ReactNativePermissionsPackage()` if not using autolinking. Clear caches and rebuild.
Could not find a declaration file for module 'react-native-permissions'. '/node_modules/react-native-permissions/lib/commonjs/index.js' implicitly has an 'any' type.
TypeScript cannot find type definitions for the module or `moduleResolution` is incorrect.
fix
Ensure `react-native-permissions` is installed correctly. For TypeScript, update `tsconfig.json` to include `"moduleResolution": "bundler"` (especially for v5.5.0+) or ensure types are correctly picked up by your IDE and bundler.
Upgrade
Version history
5.5.1latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React Native applications.
react-nativerequiredCore dependency for React Native framework.
react-native-windowsoptionalOptional peer dependency for Windows platform support.
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources