How do I request multiple permissions at once in react native

VK1 picture VK1 · Feb 22, 2019 · Viewed 8.8k times · Source

I'd like to request permissions on one page instead of waiting for each particular situation. However, I do not want multiple popups. Is there a way to ask for permissions with a single popup/modal.

On the android side I found this post and this, which look promising, but I have yet to find something for iOS.

Answer

Syed picture Syed · Feb 22, 2019

In Android

First add permissions in to the AndroidManifest.xml file and then

if (Platform.OS === 'android') {
    PermissionsAndroid.requestMultiple(
      [PermissionsAndroid.PERMISSIONS.CAMERA, 
      PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
      PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
      PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE]
      ).then((result) => {
        if (result['android.permission.ACCESS_COARSE_LOCATION']
        && result['android.permission.CAMERA']
        && result['android.permission.READ_CONTACTS']
        && result['android.permission.ACCESS_FINE_LOCATION']
        && result['android.permission.READ_EXTERNAL_STORAGE']
        && result['android.permission.WRITE_EXTERNAL_STORAGE'] === 'granted') {
          this.setState({
            permissionsGranted: true
          });
        } else if (result['android.permission.ACCESS_COARSE_LOCATION']
        || result['android.permission.CAMERA']
        || result['android.permission.READ_CONTACTS']
        || result['android.permission.ACCESS_FINE_LOCATION']
        || result['android.permission.READ_EXTERNAL_STORAGE']
        || result['android.permission.WRITE_EXTERNAL_STORAGE'] === 'never_ask_again') {
          this.refs.toast.show('Please Go into Settings -> Applications -> APP_NAME -> Permissions and Allow permissions to continue');
        }
      });
  }

In iOS In the info section of your project on XCode

  • Add the permissions and the description say - ex: Privacy - Contacts Usage Description then,

    Permissions.request('photo').then(response => {
      if (response === 'authorized') {
        iPhotoPermission = true;
      }
     Permissions.request('contact').then(response => {
      if (response === 'authorized') {
        iPhotoPermission = true;
      }
    });
    });