React-native-permissions: [iOS] Prevent app from asking "always" location permission when NSLocationAlwaysUsageDescription key is added.

Created on 30 Apr 2019  路  3Comments  路  Source: zoontek/react-native-permissions

Hi,

I only want to use "when in use" location permission but if I understand well, Apple forces me to also add NSLocationAlwaysUsageDescription key in Info.plist even if I am not using it.

When using the request code, the app display the right "when in use" dialog.

const permission = await Permissions.request("location", {
  type: "whenInUse",
});

The problem is that if I added NSLocationAlwaysUsageDescription key, as soon as I am using navigator.geolocation.getCurrentPosition the app also requests the "always" location permission.

This only happens when testing on a real device.
On the simulator it only asks for the "when in use" permission.

Is there a way to prevent that ?

  • React-Native version: 0.59.6
  • Platform: iOS
  • react-native-permissions version: 1.1.1

Most helpful comment

try to init the react-native geolocation with your required configuration using this line -

navigator.geolocation.setRNConfiguration({ skipPermissionRequests: true });

This will prevent the automatic permission request and you will have to manage the permission yourself

All 3 comments

try to init the react-native geolocation with your required configuration using this line -

navigator.geolocation.setRNConfiguration({ skipPermissionRequests: true });

This will prevent the automatic permission request and you will have to manage the permission yourself

It works. Thanks :-)

for other reading this, use this if you are using the geolocation from react native community (geolocation has moved out of rn core)

import Geolocation from '@react-native-community/geolocation'

Geolocation.setRNConfiguration({ skipPermissionRequests: true })
Was this page helpful?
0 / 5 - 0 ratings

Related issues

note89 picture note89  路  35Comments

iegik picture iegik  路  19Comments

smokinjoe picture smokinjoe  路  19Comments

vvsevolodovich picture vvsevolodovich  路  24Comments

ozturkilgim picture ozturkilgim  路  31Comments