☝🏼 React Native Permissions
Request user permissions on iOS and Android.
pull request #291 for feedbacks.
⚠️ Branch WIP 2.0.0 : Go toSupport
version | react-native version |
---|---|
2.0.0+ | 0.56.0+ |
1.1.1 | 0.40.0 - 0.52.2 |
Setup
$ npm install --save react-native-permissions# --- or --- $ yarn add react-native-permissions
iOS specific
To allow installation of the needed permission handlers for your project (and only them), react-native-permissions
uses CocoaPods. Update the following line with your path to node_modules/
and add it to your podfile:
target 'YourAwesomeProject' do # … pod 'RNPermissions', :path => '../node_modules/react-native-permissions', :subspecs => [ 'Core', ## Uncomment needed permissions # 'BluetoothPeripheral', # 'Calendars', # 'Camera', # 'Contacts', # 'FaceID', # 'LocationAlways', # 'LocationWhenInUse', # 'MediaLibrary', # 'Microphone', # 'Motion', # 'Notifications', # 'PhotoLibrary', # 'Reminders', # 'Siri', # 'SpeechRecognition', # 'StoreKit', ] end
Android specific
- Add the following lines to
android/settings.gradle
:
include ':react-native-permissions'project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
- Add the compile line to the dependencies in
android/app/build.gradle
:
dependencies { // ... implementation project(':react-native-permissions')}
- Add the import and link the package in
MainApplication.java
:
// <-- Add the import
📌 Don't forget to add permissions to AndroidManifest.xml
for android and
Info.plist
for iOS (Xcode >= 8).
API (subject to changes)
Permissions statuses
Promises resolve into one of these statuses:
Return value | Notes |
---|---|
RESULTS.UNAVAILABLE |
This feature is not available on this device. |
RESULTS.GRANTED |
The permission is granted. |
RESULTS.DENIED |
The permission has not been requested / is denied but requestable. |
RESULTS.NEVER_ASK_AGAIN |
The permission is not requestable anymore. |
Supported permissions
; // For Android // same as PermissionsAndroidANDROID_PERMISSIONSREAD_CALENDAR;ANDROID_PERMISSIONSWRITE_CALENDAR;ANDROID_PERMISSIONSCAMERA;ANDROID_PERMISSIONSREAD_CONTACTS;ANDROID_PERMISSIONSWRITE_CONTACTS;ANDROID_PERMISSIONSGET_ACCOUNTS;ANDROID_PERMISSIONSACCESS_FINE_LOCATION;ANDROID_PERMISSIONSACCESS_COARSE_LOCATION;ANDROID_PERMISSIONSRECORD_AUDIO;ANDROID_PERMISSIONSREAD_PHONE_STATE;ANDROID_PERMISSIONSCALL_PHONE;ANDROID_PERMISSIONSREAD_CALL_LOG;ANDROID_PERMISSIONSWRITE_CALL_LOG;ANDROID_PERMISSIONSADD_VOICEMAIL;ANDROID_PERMISSIONSUSE_SIP;ANDROID_PERMISSIONSPROCESS_OUTGOING_CALLS;ANDROID_PERMISSIONSBODY_SENSORS;ANDROID_PERMISSIONSSEND_SMS;ANDROID_PERMISSIONSRECEIVE_SMS;ANDROID_PERMISSIONSREAD_SMS;ANDROID_PERMISSIONSRECEIVE_WAP_PUSH;ANDROID_PERMISSIONSRECEIVE_MMS;ANDROID_PERMISSIONSREAD_EXTERNAL_STORAGE;ANDROID_PERMISSIONSWRITE_EXTERNAL_STORAGE; // new onesANDROID_PERMISSIONSANSWER_PHONE_CALLS;ANDROID_PERMISSIONSACCEPT_HANDOVER;ANDROID_PERMISSIONSREAD_PHONE_NUMBERS; // For iOS IOS_PERMISSIONSBLUETOOTH_PERIPHERAL;IOS_PERMISSIONSCALENDARS;IOS_PERMISSIONSCAMERA;IOS_PERMISSIONSCONTACTS;IOS_PERMISSIONSFACE_ID;IOS_PERMISSIONSLOCATION_ALWAYS;IOS_PERMISSIONSLOCATION_WHEN_IN_USE;IOS_PERMISSIONSMEDIA_LIBRARY;IOS_PERMISSIONSMICROPHONE;IOS_PERMISSIONSMOTION;IOS_PERMISSIONSNOTIFICATIONS;IOS_PERMISSIONSPHOTO_LIBRARY;IOS_PERMISSIONSREMINDERS;IOS_PERMISSIONSSIRI;IOS_PERMISSIONSSPEECH_RECOGNITION;IOS_PERMISSIONSSTOREKIT;
Methods
types used in usage examples
; ;
check()
Check one permission status.
Method type
;
Usage example
; ;
checkMultiple()
Check multiples permissions.
Method type
;
Usage example
; ;
request()
Request one permission.
Method type
; ; ;
Usage example
; ;
requestMultiple()
Request multiples permissions.
Method type
;
Usage example
; ;
openSettings()
Open application settings.
Method type
;
Usage example
;
🍎 iOS Notes
- Permission type
BLUETOOTH_PERIPHERAL
represents the status of theCBPeripheralManager
. - If
notificationOptions
config array is omitted onNOTIFICATIONS
request, it will requestalert
,badge
andsound
.