React-native-permissions: TypeError: Cannot read property 'check' of undefined

Created on 14 Mar 2019  Â·  5Comments  Â·  Source: zoontek/react-native-permissions

Thanks for your great work.
I'm facing this issue and to ensure if I'm not having any conflict by another plug-in or cache.. I just made a fresh dump project and then installed the package. Here is my experiment:

  • React-Native "0.59.0",
  • Platform: Android
  • Device pixel
  • OS version 9
  • react-native-permissions "^2.0.0-alpha.1"
  • Devtools: Xcode? Android Studio version?
  • (Android only: "28.0.3")

How to repeat issue and example

react-native init dump
cd dump

nmp i

instaling react-native-permissions:

npm install --save react-native-permissions
react-native link react-native-permissions

I also checked these :

_in android/settings.gradle:_

include ':react-native-permissions'
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')

_in android/app/build.gradle:_

dependencies {
  // ...
  implementation project(':react-native-permissions')
}
_in MainApplication.java:_
import com.yonahforst.rnpermissions.RNPermissionsPackage; // <-- Add the RNLocalize import 

public class MainApplication extends Application implements ReactApplication {

  // … 

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      // … 
      new RNPermissionsPackage() // <-- Add it to the packages list 
    );
  }

  // … 
}

in my app:

import Permissions from 'react-native-permissions'
...

  // Check the status of a single permission
  componentDidMount() {
    Permissions.check('photo').then(response => {
      console.log(response);
    })
  }

...
result:
screenshots

Most helpful comment

there was some change since V1
i updated it yesterday and have some trouble to make it work on android ( storage for example )

try with this syntax

           import * as RNPermissions from "react-native-permissions";
           ...
           await RNPermissions.check("storage"); // storage name was changed , i'm searching for new name too.

look her for v2 https://github.com/yonahforst/react-native-permissions/pull/291

if i understand well the doc on github first page is only for v1. please tell me if you found equivalent of "storage" for android

All 5 comments

there was some change since V1
i updated it yesterday and have some trouble to make it work on android ( storage for example )

try with this syntax

           import * as RNPermissions from "react-native-permissions";
           ...
           await RNPermissions.check("storage"); // storage name was changed , i'm searching for new name too.

look her for v2 https://github.com/yonahforst/react-native-permissions/pull/291

if i understand well the doc on github first page is only for v1. please tell me if you found equivalent of "storage" for android

I had the same problem, with v2.
import * as RNPermissions from "react-native-permissions"; did solve the issue...
Thanks!!!

@alainib thanks for your answer.
import * as RNPermissions from "react-native-permissions"; worked fine!
For me these worked for 'STORAGE':
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE

@abakhtiar thank you

On v1 we use the same arguments names on both system (ios & android) like 'camera', 'photo'.
On v2 the names are differents from what i understand. putting something like this look very dirty :

  if(Plateform.OS=='ios'){   
      let perm_resp = await RNPermissions.checkMultiple(["LOCATION_WHEN_IN_USE", "CAMERA", "PHOTO_LIBRARY"]);   
 }else{
     let perm_resp = await RNPermissions.checkMultiple([android.permission.ACCESS_FINE_LOCATION, android.permission.CAMERA, "PHOTO_LIBRARY" /* did'nt found equivalent :(*/]);   
 }

how did you manage this ?
the abstraction names in V1 was nice.

@alainib this is how it works for me:

  async checkPerms() {
    await RNPermissions.check(RNPermissions.ANDROID_PERMISSIONS.ACCESS_COARSE_LOCATION).then(result => {
      console.log("checkPerms", result);
    });

you just need to replace in the the argument(after RNPermissions) ANDROID_PERMISSIONS.ACCESS_COARSE_LOCATION with one of the followings:

// same as PermissionsAndroid
ANDROID_PERMISSIONS.READ_CALENDAR;
ANDROID_PERMISSIONS.WRITE_CALENDAR;
ANDROID_PERMISSIONS.CAMERA;
ANDROID_PERMISSIONS.READ_CONTACTS;
ANDROID_PERMISSIONS.WRITE_CONTACTS;
ANDROID_PERMISSIONS.GET_ACCOUNTS;
ANDROID_PERMISSIONS.ACCESS_FINE_LOCATION;
ANDROID_PERMISSIONS.ACCESS_COARSE_LOCATION;
ANDROID_PERMISSIONS.RECORD_AUDIO;
ANDROID_PERMISSIONS.READ_PHONE_STATE;
ANDROID_PERMISSIONS.CALL_PHONE;
ANDROID_PERMISSIONS.READ_CALL_LOG;
ANDROID_PERMISSIONS.WRITE_CALL_LOG;
ANDROID_PERMISSIONS.ADD_VOICEMAIL;
ANDROID_PERMISSIONS.USE_SIP;
ANDROID_PERMISSIONS.PROCESS_OUTGOING_CALLS;
ANDROID_PERMISSIONS.BODY_SENSORS;
ANDROID_PERMISSIONS.SEND_SMS;
ANDROID_PERMISSIONS.RECEIVE_SMS;
ANDROID_PERMISSIONS.READ_SMS;
ANDROID_PERMISSIONS.RECEIVE_WAP_PUSH;
ANDROID_PERMISSIONS.RECEIVE_MMS;
ANDROID_PERMISSIONS.READ_EXTERNAL_STORAGE;
ANDROID_PERMISSIONS.WRITE_EXTERNAL_STORAGE;

// new ones
ANDROID_PERMISSIONS.ANSWER_PHONE_CALLS;
ANDROID_PERMISSIONS.ACCEPT_HANDOVER;
ANDROID_PERMISSIONS.READ_PHONE_NUMBERS;

// For iOS

IOS_PERMISSIONS.BLUETOOTH_PERIPHERAL;
IOS_PERMISSIONS.CALENDARS;
IOS_PERMISSIONS.CAMERA;
IOS_PERMISSIONS.CONTACTS;
IOS_PERMISSIONS.FACE_ID;
IOS_PERMISSIONS.LOCATION_ALWAYS;
IOS_PERMISSIONS.LOCATION_WHEN_IN_USE;
IOS_PERMISSIONS.MEDIA_LIBRARY;
IOS_PERMISSIONS.MICROPHONE;
IOS_PERMISSIONS.MOTION;
IOS_PERMISSIONS.NOTIFICATIONS;
IOS_PERMISSIONS.PHOTO_LIBRARY;
IOS_PERMISSIONS.REMINDERS;
IOS_PERMISSIONS.SIRI;
IOS_PERMISSIONS.SPEECH_RECOGNITION;
IOS_PERMISSIONS.STOREKIT;

UPDATE
in your case(I tested with android!! so you need to change them for ios) this is working:

    await RNPermissions.checkMultiple([RNPermissions.ANDROID_PERMISSIONS.ACCESS_COARSE_LOCATION, RNPermissions.ANDROID_PERMISSIONS.CAMERA]).then(result => {
      console.log("checkPerms", result);
    });

image

Was this page helpful?
0 / 5 - 0 ratings