React-native-permissions: TypeError: undefined is not an object (evaluating 'PermissionsIOS.requestPermission')

Created on 21 Jun 2018  ·  8Comments  ·  Source: zoontek/react-native-permissions

React Native v0.55.3
iOS Simulator
react-native-permissions v1.1.1

I get the error listed in the title whenever I try to use this plugin to request location permissions on the iOS simulator. I've combed through both open and closed issues for a solution; while people seem to have had similar issues they've either gone unsolved or their solutions didn't work for me.

I've linked the project both with react-native link and manually. ReactNativePermissions.xcodeproj is listed under Libraries and libReactNativePermissions.a is linked under "Build Phases". I've included usage descriptions for the following keys;

  • Privacy - Location Always Usage Description
  • Privacy - Location When In Use Usage Description
  • Privacy - Location Always and When In Use Usage Description

As far as I can tell the issues is that I'm using RN v0.55.3, whereas the current version of the plugin supports up to v0.52. Unfortunately other dependencies prevent us from downgrading to test if that's the issue.

I dug through the source code and I think I've found the issue;

import { NativeModules } from 'react-native'
const PermissionsIOS = NativeModules.ReactNativePermissions

It seems that ReactNativePermissions isn't defined, so trying to use any of its methods results in a TypeError. Could it be that newer versions of RN to support that module? I'm not very familiar with their code base. Is there an extra step I could've missed in setting this up that isn't documented?

Update: The logic works on a physical device. Could it be that the version of JavaScript that the simulator uses differs from that of physical devices? The OS version on the simulator is 11.4.

Most helpful comment

following these directions worked for me
In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...> Go to node_modules ➜ react-native-permissions ➜ select ReactNativePermissions.xcodeproj Add libReactNativePermissions.a to Build Phases -> Link Binary With Libraries

All 8 comments

got the exact same error here with RN v.049.3.

Using the pod linking process solved it for me. I was using react-native link before, hope this helps?

I've already got that line in my podfile, no dice.

I added some console logs to the request method in the iOS permissions file and noticed that the imported NativeModules is actually an empty object. I'm not sure what I can do to fix that.

same

running pod install fixed this for me

following these directions worked for me
In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...> Go to node_modules ➜ react-native-permissions ➜ select ReactNativePermissions.xcodeproj Add libReactNativePermissions.a to Build Phases -> Link Binary With Libraries

@matthewbennett thanks that worked for me. It seems react-native link is not linking the library to the path. Thanks ☺️

Same here. No luck with just react-native link react-native-permissions, manually linked.

@matthewbennett 's Fix worked for me! This is another case of 'react-native link' ruining your day!

Was this page helpful?
0 / 5 - 0 ratings