React-native-permissions: check(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE) always returns unavailable!

Created on 13 Jul 2020  路  13Comments  路  Source: zoontek/react-native-permissions

Bug report

Summary

This problem has been opened here before and closed because the author forgot to add the Pods to the Podfile, but I didn't.

Everytime I run

const permissionStatus = await check(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);

I get 'unavailable' as a result. The odd thing is, that it does work on my Simulator where it returns 'denied' at first, then I can call request. On my actual iPhone 11 device running iOS 13 it does return 'unavailable' immediately.

I have added the descriptions to Info.plist:

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) needs your location to find items near you. A location will only be stored when you choose to by creating a post.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) needs your location to find items near you. A location will only be stored when you choose to by creating a post.</string>

I also added both Always and WhenInUse permissions to my Podfile:

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

And I have ran pod install.

Environment info

react-native info output:

info Fetching system and libraries information...
(node:12653) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
    OS: macOS 10.15.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 1.28 GB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.4.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.6 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 25, 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.0, 30.0.0
      System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: 21.2.6472646
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_252 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.0 => 0.63.0 
  npmGlobalPackages:
    *react-native*: Not Found

Library version: ^2.1.5

Steps to reproduce

  1. Add NSLocationWhenInUseUsageDescription tag to Info.plist
  2. Add Permission-LocationWhenInUse podspec to Podfile
  3. Run pod install
  4. Run app on device
  5. Call check(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE)
  6. Immediately receive unavailable for some reason

Describe what you expected to happen:

  1. I should receive denied at first so I can call request after that!

Reproducible sample code

const permissionStatus = await check(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);

Most helpful comment

1) update pod file
```
permissions_path = '../node_modules/react-native-permissions/ios'

pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
`` 2) Clean cachepod cache clean --all 3) Clean build folderXCode -> Product -> Clean build folder 4) Runpod install`

It should help

All 13 comments

And yes, I have also tested it with https://github.com/zoontek/rn-location-permission-example - same problem! It immediately returns unavailable for check().

Hi. Have you checked if Location services are enabled on your device?

width="400px" />

Yes, location services are enabled. They're also enabled for the App specifically.

Try uninstalling all applications with a similar namespace start (ex: "com.facebook") from your device, or reset your device permissions.

I've seen "unavailable" being reported for iOS camera access permissions on my iPhone 11 Pro (running iOS 13). I'm not sure what causes it (I'm sure the camera access permission in the iOS settings menu is ON). I'm working around it by ignoring "unavailable" results for devices/permission-types where I know availability is not a concern (i.e. effectively proceeding as if access is "granted").

I don't know what could cause it, but it does seem an 'unavailable' result does not necessarily mean the feature is not available on the device.

@zoontek How do I reset the device permissions? I've tried just turning it 'OFF' and then back 'ON' but that didn't fix it.

@zoontek Thanks! I tried it but it didn't make a difference.

However, I realized I forgot to add the Camera permission path to my Podfile.
pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
I haven't had a chance to try yet, but could that perhaps explain the behavior I'm seeing?

@Gra55h0pper Yes

Can we close this @Gra55h0pper @zoontek ?

Is this resolved, even I am facing this similar issue?

Same problem!! :(

Same

1) update pod file
```
permissions_path = '../node_modules/react-native-permissions/ios'

pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
pod 'Permission-Microphone', :path => "#{permissions_path}/Microphone"
`` 2) Clean cachepod cache clean --all 3) Clean build folderXCode -> Product -> Clean build folder 4) Runpod install`

It should help

Was this page helpful?
0 / 5 - 0 ratings