React-native-permissions: Invalid RNPermission 'ios.permission.LOCATION_WHEN_IN_USE'. should be one of: ( )

Created on 30 Sep 2019  ·  28Comments  ·  Source: zoontek/react-native-permissions

Bug

Invalid RNPermission 'ios.permission.LOCATION_WHEN_IN_USE'. should be one of: (
)

Environment info

System:
    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
    Memory: 161.37 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.9.0 - ~/.nvm/versions/node/v12.9.0/bin/node
    Yarn: 1.17.3 - ~/.nvm/versions/node/v12.9.0/bin/yarn
    npm: 6.10.2 - ~/.nvm/versions/node/v12.9.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
    Android SDK:
      API Levels: 25, 26, 27, 28
      Build Tools: 23.0.1, 26.0.1, 26.0.2, 27.0.0, 27.0.3, 28.0.3, 29.0.0
      System Images: android-28 | Google APIs Intel x86 Atom_64
  IDEs:
    Android Studio: 3.3 AI-182.5107.16.33.5314842
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.1 => 0.61.1 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Library version: 2.0.0

Steps To Reproduce

1) Added to Podfile

permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"

2) pod install
3) Added the permission message to info.plist
4) Rebuild the app
5)

const locationPermission = Platform.select({
  ios: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
  android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
});

const permission = await check(LOCATION_PERMISSION);

Most helpful comment

hahaha i fix it my self. Seems there is invalid data while creating a list.

I changed the code as below. And it is fixed.

RNPermissions.h

typedef NS_ENUM(NSInteger, RNPermission) {
  RNPermissionUnknown = 0,
#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
  RNPermissionBluetoothPeripheral = 1,
#endif
#if __has_include("RNPermissionHandlerCalendars.h")
  RNPermissionCalendars = 2,
#endif
#if __has_include("RNPermissionHandlerCamera.h")
  RNPermissionCamera = 3,
#endif
#if __has_include("RNPermissionHandlerContacts.h")
  RNPermissionContacts = 4,
#endif
#if __has_include("RNPermissionHandlerFaceID.h")
  RNPermissionFaceID = 5,
#endif
#if __has_include("RNPermissionHandlerLocationAlways.h")
  RNPermissionLocationAlways = 6,
#endif
#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
  RNPermissionLocationWhenInUse = 7,
#endif
#if __has_include("RNPermissionHandlerMediaLibrary.h")
  RNPermissionMediaLibrary = 8,
#endif
#if __has_include("RNPermissionHandlerMicrophone.h")
  RNPermissionMicrophone = 9,
#endif
#if __has_include("RNPermissionHandlerMotion.h")
  RNPermissionMotion = 10,
#endif
#if __has_include("RNPermissionHandlerPhotoLibrary.h")
  RNPermissionPhotoLibrary = 11,
#endif
#if __has_include("RNPermissionHandlerReminders.h")
  RNPermissionReminders = 12,
#endif
#if __has_include("RNPermissionHandlerSiri.h")
  RNPermissionSiri = 13,
#endif
#if __has_include("RNPermissionHandlerSpeechRecognition.h")
  RNPermissionSpeechRecognition = 14,
#endif
#if __has_include("RNPermissionHandlerStoreKit.h")
  RNPermissionStoreKit = 15,
#endif
};

All 28 comments

Hi @mtt87 ! I created a small repo to reproduce the issue, and it does not happen: https://github.com/zoontek/react-native-permissions-issue-326
It's probably a missing step and we could improve the documentation!

I did:

$ npx react-native init HelloPermissions
$ cd HelloPermissions
$ yarn add react-native-permissions
# Edit the `Podfile`, run `pod install`
# Edit the JS
$ open ./ios/HelloPermissions.xcworkspace

And compile (NSLocationWhenInUseUsageDescription is already existing on new projects). Everything went well.

Can you check that you followed the same steps? Check that your project looks like this? (RNPermissions + Permission-LocationWhenInUse pods)

Screenshot 2019-09-30 at 16 28 58

I tried again from scratch with

rm -rf node_modules
yarn
cd ios
pod update
pod install

and now it worked fine 🤔
I'm quite sure I did that this morning as well a few times....

Thanks for looking into it @zoontek really appreciate, I'm gonna close the issue then.

@mtt87 It might be Xcode build cache. A neat trick is Option ⌥ + Click on the Product Menu -> Clean Build Folder

Screenshot 2019-09-30 at 19 28 33

Even that clean isn't good enough. I have been bitten by stale DerivedData state a few times as well. I only use the react-native-clean-project 'wipe iOS build' option now (and I've PRd to it a couple times, including to clean DerivedData). Good luck :-)

hi,

Nothing works for me. I tried to clean up project, delete derived data, reinstall packages and pods, I've always got the error. Everything seems to be fine in my Xcode project architecture in Pods.

image

I'm using RN 0.61 with RN Permissions 2.0

@Under-Warz Can you provides more details? Cocoapods version, Xcode version, iOS version?

@zoontek of course.

System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
    Memory: 223.01 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.5.0 - ~/.nvm/versions/node/v12.5.0/bin/node
    Yarn: 1.17.3 - ~/.nvm/versions/node/v12.5.0/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v12.5.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.0, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.1 => 0.61.1 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Cocoapods : 1.7.5
Simulator iOS : 12.2

Same error here on React native 0.60.5 and Cocoapods 1.7.5. Seems like the array for checking the permission is empty.

Error is around here.

RNPermissions.h

typedef NS_ENUM(NSInteger, RNPermission) {
  RNPermissionUnknown = 0,
#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
  RNPermissionBluetoothPeripheral,
#endif
#if __has_include("RNPermissionHandlerCalendars.h")
  RNPermissionCalendars,
#endif
#if __has_include("RNPermissionHandlerCamera.h")
  RNPermissionCamera,
#endif
#if __has_include("RNPermissionHandlerContacts.h")
  RNPermissionContacts,
#endif
#if __has_include("RNPermissionHandlerFaceID.h")
  RNPermissionFaceID,
#endif
#if __has_include("RNPermissionHandlerLocationAlways.h")
  RNPermissionLocationAlways,
#endif
#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
  RNPermissionLocationWhenInUse,
#endif
#if __has_include("RNPermissionHandlerMediaLibrary.h")
  RNPermissionMediaLibrary,
#endif
#if __has_include("RNPermissionHandlerMicrophone.h")
  RNPermissionMicrophone,
#endif
#if __has_include("RNPermissionHandlerMotion.h")
  RNPermissionMotion,
#endif
#if __has_include("RNPermissionHandlerPhotoLibrary.h")
  RNPermissionPhotoLibrary,
#endif
#if __has_include("RNPermissionHandlerReminders.h")
  RNPermissionReminders,
#endif
#if __has_include("RNPermissionHandlerSiri.h")
  RNPermissionSiri,
#endif
#if __has_include("RNPermissionHandlerSpeechRecognition.h")
  RNPermissionSpeechRecognition,
#endif
#if __has_include("RNPermissionHandlerStoreKit.h")
  RNPermissionStoreKit,
#endif
};

OR

RNPermissions.m

RCT_ENUM_CONVERTER(RNPermission, (@{
#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
  [RNPermissionHandlerBluetoothPeripheral handlerUniqueId]: @(RNPermissionBluetoothPeripheral),
#endif
#if __has_include("RNPermissionHandlerCalendars.h")
  [RNPermissionHandlerCalendars handlerUniqueId]: @(RNPermissionCalendars),
#endif
#if __has_include("RNPermissionHandlerCamera.h")
  [RNPermissionHandlerCamera handlerUniqueId]: @(RNPermissionCamera),
#endif
#if __has_include("RNPermissionHandlerContacts.h")
  [RNPermissionHandlerContacts handlerUniqueId]: @(RNPermissionContacts),
#endif
#if __has_include("RNPermissionHandlerFaceID.h")
  [RNPermissionHandlerFaceID handlerUniqueId]: @(RNPermissionFaceID),
#endif
#if __has_include("RNPermissionHandlerLocationAlways.h")
  [RNPermissionHandlerLocationAlways handlerUniqueId]: @(RNPermissionLocationAlways),
#endif
#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
  [RNPermissionHandlerLocationWhenInUse handlerUniqueId]: @(RNPermissionLocationWhenInUse),
#endif
#if __has_include("RNPermissionHandlerMediaLibrary.h")
  [RNPermissionHandlerMediaLibrary handlerUniqueId]: @(RNPermissionMediaLibrary),
#endif
#if __has_include("RNPermissionHandlerMicrophone.h")
  [RNPermissionHandlerMicrophone handlerUniqueId]: @(RNPermissionMicrophone),
#endif
#if __has_include("RNPermissionHandlerMotion.h")
  [RNPermissionHandlerMotion handlerUniqueId]: @(RNPermissionMotion),
#endif
#if __has_include("RNPermissionHandlerPhotoLibrary.h")
  [RNPermissionHandlerPhotoLibrary handlerUniqueId]: @(RNPermissionPhotoLibrary),
#endif
#if __has_include("RNPermissionHandlerReminders.h")
  [RNPermissionHandlerReminders handlerUniqueId]: @(RNPermissionReminders),
#endif
#if __has_include("RNPermissionHandlerSiri.h")
  [RNPermissionHandlerSiri handlerUniqueId]: @(RNPermissionSiri),
#endif
#if __has_include("RNPermissionHandlerSpeechRecognition.h")
  [RNPermissionHandlerSpeechRecognition handlerUniqueId]: @(RNPermissionSpeechRecognition),
#endif
#if __has_include("RNPermissionHandlerStoreKit.h")
  [RNPermissionHandlerStoreKit handlerUniqueId]: @(RNPermissionStoreKit),
#endif
}), RNPermissionUnknown, integerValue);

@Under-Warz @kkusanagi Could you check that CocoaPods is properly integrated in your project and add Headers search paths automatically?

Screenshot 2019-10-02 at 14 48 21

(This is what CocoaPods does normally by default)

Also, try:

$ pod deintegrate
$ rm -rf *.xcworkspace
$ pod install

And open the new xcworkspace file, compile.

hahaha i fix it my self. Seems there is invalid data while creating a list.

I changed the code as below. And it is fixed.

RNPermissions.h

typedef NS_ENUM(NSInteger, RNPermission) {
  RNPermissionUnknown = 0,
#if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
  RNPermissionBluetoothPeripheral = 1,
#endif
#if __has_include("RNPermissionHandlerCalendars.h")
  RNPermissionCalendars = 2,
#endif
#if __has_include("RNPermissionHandlerCamera.h")
  RNPermissionCamera = 3,
#endif
#if __has_include("RNPermissionHandlerContacts.h")
  RNPermissionContacts = 4,
#endif
#if __has_include("RNPermissionHandlerFaceID.h")
  RNPermissionFaceID = 5,
#endif
#if __has_include("RNPermissionHandlerLocationAlways.h")
  RNPermissionLocationAlways = 6,
#endif
#if __has_include("RNPermissionHandlerLocationWhenInUse.h")
  RNPermissionLocationWhenInUse = 7,
#endif
#if __has_include("RNPermissionHandlerMediaLibrary.h")
  RNPermissionMediaLibrary = 8,
#endif
#if __has_include("RNPermissionHandlerMicrophone.h")
  RNPermissionMicrophone = 9,
#endif
#if __has_include("RNPermissionHandlerMotion.h")
  RNPermissionMotion = 10,
#endif
#if __has_include("RNPermissionHandlerPhotoLibrary.h")
  RNPermissionPhotoLibrary = 11,
#endif
#if __has_include("RNPermissionHandlerReminders.h")
  RNPermissionReminders = 12,
#endif
#if __has_include("RNPermissionHandlerSiri.h")
  RNPermissionSiri = 13,
#endif
#if __has_include("RNPermissionHandlerSpeechRecognition.h")
  RNPermissionSpeechRecognition = 14,
#endif
#if __has_include("RNPermissionHandlerStoreKit.h")
  RNPermissionStoreKit = 15,
#endif
};

@zoontek I can't find any headers about RNPermission and permissions itself (pod update && pod install has been made)

image

@kkusanagi I will made a minor release tomorrow with the fix, thanks!

@Under-Warz Do you use use_frameworks! ? I think it's linked.

EDIT: It does not seems to solve all cases (use_frameworks! ones). Related issues: #331 https://github.com/facebook/react-native/issues/26333

This is still an issue when using use_frameworks!, correct? I've tried the solutions mentioned and still get this error. Also, https://github.com/facebook/react-native/issues/26333 is fixed in 0.61.1 and #331 is not an issue for me. Is there perhaps a workaround, such as manual Framework Search Header path entries?

@timmywil If none of the solutions worked for you, can you open a new issue with some infos on your setup (RN version, CocoaPods version, your Podfile?). It will be easier to help you 🙂

@zoontek I have the same issue. RNPermissions does not see RNPermissionHandlerX.
Also, to check, I tried to import it manually RNPermissions, and I could not...
But I can do it from:

import "PhotoLibrary/RNPermissionHandlerPhotoLibrary.m"

This is interesting

I had to add "${PODS_CONFIGURATION_BUILD_DIR}/Permission-X" to RNPermissions "Framework Search Paths" to make it works :)
@Under-Warz thank you for your suggestion 👍

@Under-Warz but in this way, I should always add it manually.
How can I achieve "automated" linking.
I'm playing with postinstall script in Podfile now.

@chelovekdrakon I didn't suggest anything but you're welcome if it's helped you ^^

For now I'm stop using this lib for my dev but I'll back on it later.

@zoontek sry for the delay, yes I'm also using use_frameworks! with an iOS native project already developed

I'm not sure this may be cause. Starting on react-native 0.61 above, the react native developer had removed the react.xproject (something) from the library. and this may cause a lot of trouble for other library that use this library. I'm meet this issue with realm. so i need to downgrade to 0.60.5 with fresh setup.

If you downgrade from 0.61, you need to add back the react.xproject back to ios library.

I tried again from scratch with

rm -rf node_modules
yarn
cd ios
pod update
pod install

and now it worked fine 🤔
I'm quite sure I did that this morning as well a few times....

Thanks for looking into it @zoontek really appreciate, I'm gonna close the issue then.

rm -rf node_modules
yarn
cd ios
pod update
pod install
react-native run-ios
I'm as good as you. I don't know how many times I repeat the operation。

this is happening to me as well,
seems like the permission handlers imports are not valid (for example if i try to import RNPermissionHandlerLocationWhenInUse.h, the xcode gives error message saying it does not finds the files), hence, the enum gets translated to an empty enum.
how can we fix that?

@menesh2 what version you are using for react-native-permissions and React Native?
I'm using react-native-permissions:2.0.2 and react-native: 0.60.5

it work just fined.

@kkusanagi
React Native: 0.61.4,
react-native-permissions: 2.0.4

I had the same issue but I realized that I forgot to add a permission handler in the Podfile ^^
Add one of the handlers you want to check then everything should work again.

pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
pod install

@ozgurchn i have those handlers in my podfile:

image

do you have another idea?

@menesh2 https://github.com/react-native-community/react-native-permissions#%EF%B8%8F-if-you-encounter-the-error-invalid-rnpermission-x-should-be-one-of-

@zoontek

@menesh2 https://github.com/react-native-community/react-native-permissions#%EF%B8%8F-if-you-encounter-the-error-invalid-rnpermission-x-should-be-one-of-

tried it already, unfortunately it did not help

I had to add "${PODS_CONFIGURATION_BUILD_DIR}/Permission-X" to RNPermissions "Framework Search Paths" to make it works :)
@Under-Warz thank you for your suggestion 👍

After adding the pods to the Podfile, this ended up fixing the issue for me. Thanks 👍

Was this page helpful?
0 / 5 - 0 ratings