iOS Development

android – ‘RNPermissionsModule’ couldn’t be discovered. Invariant Violation: TurboModuleRegistry.getEnforcing(…)

Spread the love


I’m attempting to construct an utility that opens a digicam after asking for permission. I’m utilizing ‘react-native-permissions’ and evidently it can not discover the RNPermissionsModule. I’m testing it on an android cellphone. At the moment, I’ve v4.0.4 of ‘react-native-permissions’

Right here is one other error that is related with the primary difficulty:
[TypeError: Cannot read property 'PERMISSIONS' of undefined]

Right here is my Permissions.js

import { Alert, Platform } from 'react-native';
import { examine, PERMISSIONS, RESULTS, request, openSettings } from 'react-native-permissions';

export const isIOS = Platform.OS === 'ios';

perform showAlert(msg) {
    Alert.alert('', msg, [
        {
            text: 'Cancel',
            onPress: () => console.log('Cancel Pressed'),
            style: 'cancel',
        },
        {
            text: 'Settings',
            onPress: () => {
                openSettings().catch(() => console.warn('cannot open settings'));
            },
        },
    ]);
}

const hasCameraPermission = async (withAlert = true) => {
    attempt {
        const permission = isIOS
            ? PERMISSIONS.IOS.CAMERA
            : PERMISSIONS.ANDROID.CAMERA;
        const response = await examine(permission);
        let digicam;
        if (response.digicam !== RESULTS.GRANTED) {
            digicam = await request(permission);
        }
        if (digicam === RESULTS.DENIED || digicam === RESULTS.BLOCKED) {
            if (withAlert) {
                showAlert(
                    'Permission not granted for Digicam. Unable to make use of digicam on this utility.',
                );
            }
            return false;
        }
        return true;
    } catch (error) {
        console.log(error);
        return false;
    }
};

const hasPhotoPermission = async (withAlert = true) => {
    attempt {
        const permission = isIOS
            ? PERMISSIONS.IOS.PHOTO_LIBRARY
            : PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE_StorageService;
        const response = await examine(permission);
        let picture;
        if (response.picture !== RESULTS.GRANTED) {
            picture = await request(permission);
        }
        if (picture === RESULTS.DENIED || picture === RESULTS.BLOCKED) {
            if (withAlert) {
                showAlert(
                    'Permission not granted for pictures. Unable to get pictures on this utility.',
                );
            }
            return false;
        }
        return true;
    } catch (error) {
        console.log(error);
        return false;
    }
};

const PermissionsService = {
    hasCameraPermission,
    hasPhotoPermission,
}

export default PermissionsService;

This is what I’ve tried:

  • Reinstalling ‘react-native-permissions’
  • Downgrading ‘react-native-permissions’
  • cleansing the cache
  • Verify if RNPermissionsModule is registered utilizing
const { NativeModules } = require('react-native');

  if (NativeModules.RNPermissionsModule) {
    console.log('RNPermissionsModule is registered!');
  } else {
    console.log('RNPermissionsModule not discovered');
  }

Output: RNPermissionsModule not discovered

2 thoughts on “android – ‘RNPermissionsModule’ couldn’t be discovered. Invariant Violation: TurboModuleRegistry.getEnforcing(…)

Leave a Reply

Your email address will not be published. Required fields are marked *