HomeiOS Developmentandroid - 'RNPermissionsModule' couldn't be discovered. Invariant Violation: TurboModuleRegistry.getEnforcing(...)

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


I’m making an attempt to construct an software that opens a digital camera after asking for permission. I’m utilizing ‘react-native-permissions’ and plainly it can’t discover the RNPermissionsModule. I’m testing it on an android cellphone. Presently, I’ve v4.0.4 of ‘react-native-permissions’

Right here is one other error that is related with the primary situation:
[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';

operate 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 digital camera;
        if (response.digital camera !== RESULTS.GRANTED) {
            digital camera = await request(permission);
        }
        if (digital camera === RESULTS.DENIED || digital camera === RESULTS.BLOCKED) {
            if (withAlert) {
                showAlert(
                    'Permission not granted for Digicam. Unable to make use of digital camera on this software.',
                );
            }
            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 photograph;
        if (response.photograph !== RESULTS.GRANTED) {
            photograph = await request(permission);
        }
        if (photograph === RESULTS.DENIED || photograph === RESULTS.BLOCKED) {
            if (withAlert) {
                showAlert(
                    'Permission not granted for pictures. Unable to get pictures on this software.',
                );
            }
            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
  • Test 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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments