Configure Windows Setup
masterwindows folder. In your app project, open the Package.appxmanifest file to select the capabilities your app needs to support.repository·master·Indexed 26 days ago
https://github.com/zoontek/react-native-permissionsA unified permissions API for React Native providing a consistent interface for requesting and checking permissions across iOS, Android, and Windows. Version 5.6.1 includes support for individual and multiple permission checks, notification-specific handling, and system settings navigation via openSettings(). It provides specialized configuration for iOS Podfiles, Android Manifests, and Expo config plugins.
windows folder. In your app project, open the Package.appxmanifest file to select the capabilities your app needs to support.To manually link on Android, follow these three steps:
android/settings.gradle to include the project.android/app/build.gradle.RNPermissionsPackage in MainApplication.java within the getPackages method.// 1. android/settings.gradle
include ':react-native-permissions'
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
// 2. android/app/build.gradle
dependencies {
// ...
implementation project(':react-native-permissions')
}
// 3. MainApplication.java
import com.zoontek.rnpermissions.RNPermissionsPackage;
// ... inside getPackages()
packages.add(new RNPermissionsPackage());Install the package using npm or yarn to begin using the unified permissions API on iOS, Android, and Windows.
$ npm i -S react-native-permissions
# --- or ---
$ yarn add react-native-permissionsThe library abstracts platform differences (iOS, Android, Windows) using a specific logic flow for check and request operations:
check(PERMISSIONS.X.Y):
RESULTS.UNAVAILABLE.RESULTS.GRANTED or RESULTS.LIMITED.RESULTS.BLOCKED.RESULTS.DENIED.request(PERMISSIONS.X.Y):
RESULTS.GRANTED or RESULTS.LIMITED.RESULTS.BLOCKED.check first.granted: Proceed with the feature.blocked: Prompt the user to open system settings using openSettings (Note: openSettings does not show on Android).denied: Show a UI element (like a button) to trigger request.request: If the result is blocked, prompt the user to go to settings via openSettings.By default, no permissions are available on iOS. You must configure your Podfile to include the required permissions and update your Info.plist with usage descriptions.
node_require helper to resolve scripts and call setup_permissions with an array of the specific permissions your app requires.pod install in your ios directory. Note: You must re-execute this command every time you update the setup_permissions configuration.NSCameraUsageDescription) for every permission specified in your Podfile.# In your Podfile
def node_require(script)
require Pod::Executable.execute_command('node', ['-p',
"require.resolve('
'#{script}',
{paths: [process.argv[1]]},
)", __dir__]).strip
end
node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')
setup_permissions([
'Camera',
'Microphone',
])For Windows integration, follow these steps in Visual Studio:
windows/myapp.sln, right-click the Solution icon, select Add > Existing Project, and choose node_modules\react-native-permissions\windows\RNPermissions\RNPermissions.vcxproj.windows/myapp/myapp.vcxproj, right-click the main application project, select Add > Reference..., and check RNPermissions.#include "winrt/RNPermissions.h" to your pch.h file.app.cpp, add PackageProviders().Append(winrt::RNPermissions::ReactPackageProvider()); before the InitializeComponent(); call.If using Expo, do not follow the standard iOS/Android manual setup steps. Instead, update your Expo configuration (app.config.js or app.json) using the react-native-permissions plugin.
app.config.js/ts): Import permissions from react-native-permissions/expo and add it to the plugins array. Specify iosPermissions and android.permissions.app.json): Add react-native-permissions to the plugins array.Podfile setup (steps 1-3 in the iOS section) and add infoPlist descriptions.// app.config.ts example
import permissions from 'react-native-permissions/expo';
export default {
plugins: [
permissions({
iosPermissions: ['Camera', 'Microphone'],
}),
],
ios: {
infoPlist: {
NSCameraUsageDescription: '[REASON]',
NSMicrophoneUsageDescription: '[REASON]',
},
},
android: {
permissions: ['android.permission.CAMERA', 'android.permission.RECORD_AUDIO'],
},
};To enable permissions on Android, add the desired <uses-permission> tags to your android/app/src/main/AndroidManifest.xml file. Only include the permissions that your application actually uses.
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Add permissions here -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
</manifest>To test permission logic in Jest, add the following to your jest.setup.js file to mock the native module:
jest.mock('react-native-permissions', () => require('react-native-permissions/mock'));Ensure your Jest configuration includes the setup file:
setupFiles: ['<rootDir>/jest.setup.js'];If your project requires manual linking, add the RNPermissions pod to your ios/Podfile and then run pod install.
target 'YourAwesomeProject' do
# …
pod 'RNPermissions', :path => '../node_modules/react-native-permissions'
endTo enable specific permissions in your iOS project, you must use the setup_permissions function within your Podfile. This script automates the configuration of the RNPermissions.podspec by updating s.source_files and s.frameworks based on the permissions you explicitly request.
To use it, call setup_permissions and pass an array of permission names that correspond to the directory names in the ios/ folder of the package.
Available Permission Keys:
AppTrackingTransparencyBluetoothCalendarsCalendarsWriteOnlyCameraContactsFaceIDLocationAccuracyLocationAlwaysLocationWhenInUseMediaLibraryMicrophoneMotionNotificationsPhotoLibraryPhotoLibraryAddOnlyRemindersSiriSpeechRecognitionStoreKitreact-native-permissions with an Expo project, use the withPermissions config plugin. This plugin allows you to configure the necessary native permissions (such as AppTrackingTransparency, Bluetooth, Calendars, etc.) within your app.json or app.config.js during the prebuild process.