React-native-permissions: use_frameworks in Podfile may cause Invalid RNPermission 'ios.permission.LOCATION_WHEN_IN_USE

Created on 10 Oct 2019  Β·  44Comments  Β·  Source: zoontek/react-native-permissions

Bug

Invalid RNPermission
β€˜ios.permission.LOCATION_WHEN_IN_USE’:
Should be one of: (
)

May be related to use_frameworks!

Environment info

React native info output:

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 1.28 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.10.0 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.11.3 - /usr/local/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.1 AI-173.4819257
    Xcode: 11.0/11A420a - /usr/bin/xcodebuild
  npmPackages:
    react: 16.10.2 => 16.10.2 
    react-native: 0.61.2 => 0.61.2 
  npmGlobalPackages:
    create-react-native-app: 1.0.0
    react-native-cli: 2.0.1
    react-native-git-upgrade: 0.2.7

Library version: 2.0.2

Steps To Reproduce

  1. Init new RN project
  2. Add pods for this Library
  3. Add use_frameworks! in Podfile
  4. Add code to request location
  5. Run in simulator
    ...

Describe what you expected to happen:

1.Permissions should be requested.

What does happen:
Red box error on iOS simulator
image

Reproducible sample code

Git repo: https://github.com/algera/perm

JavaScript

import React, { Component } from 'react';
import {
  Text,
} from 'react-native';
import { request, PERMISSIONS } from 'react-native-permissions'

class App extends Component {

  async componentDidMount(){
    const some = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE)    
  }

  render() {
        return (
      <Text style={{
        marginTop: 100,
        marginLeft: 100
      }}>PERM Tester</Text>
    );
  }
}


export default App;

Related issues:
https://github.com/react-native-community/react-native-permissions/issues/326
https://github.com/react-native-community/react-native-permissions/issues/339
https://github.com/react-native-community/react-native-permissions/issues/331
https://github.com/react-native-community/react-native-permissions/issues/342

bug

Most helpful comment

@zoontek yes, I did a npx react-native-clean-project with all options enabled and still facing the issue

All 44 comments

Please post your Podfile

Also, have you tried npx react-native-clean-project ? This is a build state issue sometimes, that module is ace at cleaning out stale Xcode items.

Sorry - I see you posted a repo! Fantastic, no one does that :-)

Podfile looks good. My hunch is Xcode staleness, but maybe a use_frameworks issue...

Def could be an Xcode staleness. I have this problem in a separate project and so I tried recreating using a new project - but same Xcode. I did follow some cleanup tasks as referenced in the other issues. Will try the npx.

Reinstalling Xcode in its entirety and rm -rf on ~/Library/Developer/* Will report back after completion.

Well that's a little drastic! I have consistent success with the react-native-clean-project, it's sufficient. On the other hand I'm battling some wierd "Xcode 11.1 won't install" issue so maybe you're just doing my next step trying to resolve that unrelated thing?

  1. Xcode reinstall coupled with cache removal on Developer and CocaoPods dirs
  2. Tried the react-native-clean-project
    To no avail
    Removed the use_frameworks! in the pods, ran pod clean and pod install and that worked

image

So to me, seems to be related to use_frameworks!. Will investigate further tomorrow. the clean project command had a couple of errors / warnings so that's why I went all the way and went to as clean of a slate as I could. On a side note, I did successfully "upgrade" (i.e. reinstall) to Xcode 11.1 πŸ˜„

Well that is a great, solid information but unfortunately is the more difficult result, as use_frameworks has been in flux for a while. Only RN61+ can do it, and then there may be a layer of issues exposed related to modules

FWIW, I've been using use_frameworks! since RN 0.5x but yes, it has been an issue from time to time on other libs. Since our app is brownfield, we require other pods/code which require this flag.

Same issue, tried cleaning all of XCode directories, checked Info.plist and even restarted the project to rule out any issue related to my computer. 😭 We don't use use_frameworks! at all.

It's linked through pods:

pod 'RNPermissions', :path => '../node_modules/react-native-permissions'

No other permission types work.

I understand that my report is vague, I would welcome any idea on what I can do to get to the bottom of this. I'm not afraid to mess with Objective-C if it helps with development.

FYI, this issue was quickly fixed for me by cleaning XCode's build folder via Product > Clean Build Folder.

Rebuilding my project then proved to fix the issue!

@inf3rnus can you confirm you are using the use_frameworks in your pod file?

Managed to reproduce the issue again and fix it in XCode 11. Worked well in XCode 10 throughout.

I was missing permission pods. Perhaps we should emphasize stronger that users need to add permission pods and add a note to the warning section informing that missing permission pods can be the cause:

⚠️ If you have the error Invalid RNPermission X. Should be one of: (), make sure you have permission pods added, try to cleanup Xcode stale data with npx react-native-clean-project --remove-iOS-build --remove-iOS-pods && rm -fr ./node_modules

I believe this issue is specific when β€˜use_frameworks!’ flag is enabled. I’ll update the title to reflect this specification.

In my case use_frameworks! was disabled.

XCode 10 would work without specific permission pods:
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral.podspec"

But XCode 11 doesn't.

Adding the relevant permission handlers resolved this for me.

@Soni96pl Thanks for pointing me in the right direction. I second your suggestion to add this to the warning. Although this is very clearly documented in the installation instructions, I was so focused on the idea of stale data that I missed my simple setup error.

Sorry if my mention of the stale data took you off track - I will submit that using react-native-clean-project is sort of liberating in that I can focus on stale data, but if the problem persists after running that, I can then immediately let it go and hunt elsewhere - I've never had caching issues with react-native-clean-project in it's current form so I am pretty confident I'm at least "cache clean" after running it

Same issue, tried cleaning all of XCode directories, checked Info.plist and even restarted the project to rule out any issue related to my computer. 😭 We don't use use_frameworks! at all.

It's linked through pods:

pod 'RNPermissions', :path => '../node_modules/react-native-permissions'

No other permission types work.

I understand that my report is vague, I would welcome any idea on what I can do to get to the bottom of this. I'm not afraid to mess with Objective-C if it helps with development.

Which version of React Native do you use? It's not needed to link the core with autolinking feature (0.60+), and worst could create duplicate symbols issues (linked twice)

0.59.9 😞 We'll move onto 0.60 when this project is over, hopefully.

@Soni96pl Thanks for pointing me in the right direction. I second your suggestion to add this to the warning. Although this is very clearly documented in the installation instructions, I was so focused on the idea of stale data that I missed my simple setup error.

It's easy to fall in this pitfall as it works without in XCode 10, so for someone that had it setup, and it was working, they'd see the warning and skip anything else πŸ™‚

@Soni96pl Check this workaround to manually link permission handlers: https://github.com/react-native-community/react-native-permissions/issues/348#issuecomment-541423154

@zoontek I've tried all of these "clean up" approaches but my "RNPermissions" still do not see other "../Permission-X" dependencies. --> The same error
I even can not understand how all of these cleanups should help the library to "see" the others (submodules) to use.
I've tried to add them to "Framework Search Paths" in RNPermissions --> Then it starts to see them and able to use, but it becomes a "circle" linking since submodules have "RNPermission" as dependency

Or it is the issue of RCTConvert?

@algera To confirm, I am not using useframeworks!

@algera There're no particular issues without use_frameworks!, just Xcode junk πŸ™‚

But the issue with use_frameworks! is real and more likely tied to CocoaPods. I ask for help in the React Native Community discord πŸ˜…

@chelovekdrakon Which version of RN do you use? Can you send your Podfile?

I installed the latest version of react-native-permissions and I don't have use_frameworks! and it is not working for me and throwing the same issue...

@DaniAkash You did a npx react-native-clean-project --remove-iOS-build --remove-iOS-pods ?

@zoontek version of RN - 0.61.
Here is Podfile:
```source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

project './sharekey.xcworkspace'

def project_pods
# React
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/'
pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

# React Community
pod 'react-native-branch', path: '../node_modules/react-native-branch'
pod 'Branch'
# pod 'Branch-SDK', path: '../node_modules/react-native-branch'
pod 'react-native-onesignal', :path => '../node_modules/react-native-onesignal'

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

# Uncoment Permission you need and describe it in Info.plist
# pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral.podspec"
# pod 'Permission-Calendars', :path => "#{permissions_path}/Calendars.podspec"
# pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts.podspec"
# pod 'Permission-FaceID', :path => "#{permissions_path}/FaceID.podspec"
# pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
# pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"
# pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary.podspec"
# pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone.podspec"
# pod 'Permission-Motion', :path => "#{permissions_path}/Motion.podspec"
# pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
# pod 'Permission-Reminders', :path => "#{permissions_path}/Reminders.podspec"
# pod 'Permission-Siri', :path => "#{permissions_path}/Siri.podspec"
# pod 'Permission-SpeechRecognition', :path => "#{permissions_path}/SpeechRecognition.podspec"
# pod 'Permission-StoreKit', :path => "#{permissions_path}/StoreKit.podspec"

use_native_modules!

pod 'TweetNacl', :git => 'ssh://[email protected]/sharekey/tweetnacl-swiftwrap.git'
pod 'Instabug'
pod 'NAChloride'
pod 'BSImagePicker'

end

target 'sharekey' do
project_pods

target 'OneSignalNotificationServiceExtensionProd' do
    inherit! :search_paths
    pod 'OneSignal', '>= 2.9.3', '< 3.0'
    # Pods for testing
end

end

target 'sharekey staging' do
project_pods

target 'OneSignalNotificationServiceExtensionStaging' do
    inherit! :search_paths
    pod 'OneSignal', '>= 2.9.3', '< 3.0'
    # Pods for testing
end

end

target 'sharekey dev' do
project_pods
end

target 'sharekey alpha' do
project_pods

target 'OneSignalNotificationServiceExtensionAlpha' do
    inherit! :search_paths
    pod 'OneSignal', '>= 2.9.3', '< 3.0'
    # Pods for testing
end

end

post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "libsodium"
target.build_configurations.each do |config|
config.build_settings['USE_HEADERMAP'] = false
end
end
end
end```

@chelovekdrakon If you delete sharekey.xcworkspace and the project './sharekey.xcworkspace' line to let Cocoapods generate it for you, do you still have issues?

@zoontek yes, I did a npx react-native-clean-project with all options enabled and still facing the issue

@zoontek
Yep, the same with this approach :/

@DaniAkash @chelovekdrakon Please provide minimal repositories to reproduce the error.

@zoontek Ok ;) I will try to repro on another repo!

@zoontek Thanks! I'm actually fine using CocoaPods, I was actually able to resolve this issue previously and was expanding on it to provide a suggestion for the warning:
https://github.com/react-native-community/react-native-permissions/issues/346#issuecomment-541374539

Perhaps it is something worth looking into as XCode 10 doesn't require permission pods same way XCode 11 does so we'll have more users falling into this trap as they upgrade their environment.

@Soni96pl Great, didn't see your comment. It could be nice to improve the readme a bit yes.

A note of progress. use_frameworks! is no longer required in my project. I removed this qualifier and added :modular_headers => true lines where necessary (on each pod using a Swift-style import). I can close this issue if we'd like. If we do close, I suggest would then be to add "use_frameworks! within your Podfile is not supported for this library and may not be required for Swift files as of Cocoapods 1.5.0 (see http://blog.cocoapods.org/CocoaPods-1.5.0/)" in README.md.

I have the same issue using use_frameworks! It would be a big effort on our side supporting the cocoapods 1.5.0. I will try working on that it would would be much easier if it would work with this lib !

I replaced use_frameworks! by use_modular_headers! finally for it working! πŸ‘

@algera or anyone else
guys I am using RN : 0.59.9(the project is in progress from July this year)
I have added all the React-Native libraries manually(they are list down under Libraries folder)
Every thing is working fine except this library and I am getting the same error on Xcode 11

@algera I added a mention of use_frameworks! / use_modular_headers! with a link to the Cocoapods website directly in the README, encouraging users to switch to the second one.

I'm having this same issue. It looks like the above solution is to stop using use_frameworks, but is there a way to get this package to work if another package I'm using relies on use_frameworks? I've tried replacing with use_modular_headers and react-native-clean-project and neither worked for me.

Hey guys. The issue is still there. This library does not works with use_frameworks!
Many cocoapods dependencies are dynamic frameworks and could not be used as static framework with use_modular_headers
Have tested example project on version 2.0.3 with added use_frameworks!

Setting use_modular_headers! globally in the Podfile wasn't an option for me (RN 0.61.5), however, taking a look at the Cocoapods docs, this can be set on an individual pod basis. I updated my Podfile with the following change and everything seemed to work ok. If you are requiring more permissions than I currently am, make sure to add :modular_headers => true for each one.

...
# Required by react-native-permissions
permissions_path = '../node_modules/react-native-permissions/ios'

pod 'Permission-LocationWhenInUse', :modular_headers => true, :path => "#{permissions_path}/LocationWhenInUse.podspec"
...

Setting use_modular_headers! globally in the Podfile wasn't an option for me (RN 0.61.5), however, taking a look at the Cocoapods docs, this can be set on an individual pod basis. I updated my Podfile with the following change and everything seemed to work ok. If you are requiring more permissions than I currently am, make sure to add :modular_headers => true for each one.

...
# Required by react-native-permissions
permissions_path = '../node_modules/react-native-permissions/ios'

pod 'Permission-LocationWhenInUse', :modular_headers => true, :path => "#{permissions_path}/LocationWhenInUse.podspec"
...

@bonesyblue Added the above lines to my podfile but it still didn't fix the issue. Will create a reproducable repository and raise another issue

Hi @DaniAkash . try to use info from https://github.com/react-native-community/react-native-permissions/pull/372
you could specify which of dependencies should be linked as static_library or dynamic_framework

The packages I'm using are _react-native-permissions, react-native-geolocation-service, @react-native-community/geolocation_ and _@react-native-mapbox-gl/maps_. My problem was the same problem as @algera, and mainly, the problem was about using use_frameworks! (that is needed for mapbox) and, also, using use_frameworks! with react-native-permissions was causing the error: Invalid RNPermission ios.permission.LOCATION_WHEN_IN_USE. Then I had to find an alternative to use mapbox and react-native-permissions at the same time (without using use_frameworks!)

So what I did to fix was follow what was stated in react-native-permissions installation setup for iOS (https://github.com/react-native-community/react-native-permissions#%EF%B8%8F-if-you-encounter-the-error-invalid-rnpermission-x-should-be-one-of-), and after that following react-native-mapbox setup for alternatives to using mapbox with use_frameworks! (https://github.com/react-native-mapbox-gl/maps/blob/master/ios/install.md and https://github.com/react-native-mapbox-gl/maps/pull/714)

My final Podfile was like this:

platform :ios, '9.0'
use_modular_headers!
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'YOUR-APP' do
  # react native mapbox-gl
  pod 'react-native-mapbox-gl', :path => '../node_modules/@react-native-mapbox-gl/maps'
  pod 'NoUseFrameworks-MapboxMobileEvents',  :podspec => '../node_modules/@react-native-mapbox-gl/maps/ios/NoUseFrameworks-MapboxMobileEvents/NoUseFrameworks-MapboxMobileEvents.podspec.json'
  # react native permissions
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-LocationAlways', :path => "#{permissions_path}/LocationAlways.podspec"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"
  # Pods for YOUR-APP
(...)

Hope it helps someone!

Was this page helpful?
0 / 5 - 0 ratings