1

Issue Description I am working on tracking app and want to enable "always" location permission when user start it's tracking service. Here I am building path traveled by user, so I want to detect latitudes and longitudes even if app is background. Now problem occurs when user chooses location option as "while app in use", in this I am not getting exact latitude and longitude for user when app is in background and creating issues. In this case I am not able to build a proper track for user.

To do this I have added only

"NSLocationAlwaysUsageDescription"

but it generates error::

This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys with string values explaining to the user how the app uses this data

To resolve this I have to add all the permission, which work fine in my case. But now user is getting three option while enabling location:: "allow while using app", "always allow" and "don't allow". Here the problem occur.

Requirement I want to restrict user to only enables the "always" location option, but now location request popup is showing three option. Is there any method to detect selected option by user, if user will select any option other than always I will tell him to choose "always" when working on tracking system.

1.Basically I want to detect the selected location option of user, and if it is not "always" I want to request him again to choose "always" location option. Is this possible?

2.I want to add "always" option inside request service popup, currently I am getting these three values:: "allow while using app", "allow once" and "don't allow". I have added permissions in a format::

<key>NSLocationUsageDescription</key>
<key>NSLocationAlwaysUsageDescription</key>
<key>NSLocationWhenInUseUsageDescription</key>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>

but it's showing only three value check this screenshot::

enter image description here

Archana Sharma
  • 1,953
  • 6
  • 33
  • 65

1 Answers1

4

You could use react-native-permissions:

import Permissions, { PERMISSIONS, RESULTS } from 'react-native-permissions'

const permissionStatus = await Permissions.check(PERMISSIONS.IOS.LOCATION_ALWAYS)

permissionsStatus is gonna be one of RESULTS possible values:

enter image description here

Charles Mangwa
  • 183
  • 2
  • 6
  • 1
    Hey I have already used this , but getting this response `"ios.permission.LOCATION_ALWAYS permission checked: denied"`. Any solution?? – Archana Sharma Jan 23 '20 at 12:46
  • And what if permission status is "blocked"?? – Archana Sharma Jan 23 '20 at 12:52
  • 2
    Then I'd suggest you display your users a message explaining why you need that specific permission with a "Grant permission" button for instance. The callback of such button would be `Linking.openURL('app-settings:')` (`Linking` is from `react-native`) which is going to directly open your app settings in the iOS Settings app. From there they'll be able to manually grant the permission. Note that if the permission was `'denied'`, having the user manually enabling it is the only thing you can do on iOS if I'm not mistaken (Apple doesn't allow you to programmatically change it by yourself). – Charles Mangwa Jan 23 '20 at 13:46
  • I am doing the same thing right now, opening a setting for that user. But I thought we can do this programmatically. – Archana Sharma Jan 24 '20 at 03:10
  • 1
    `react-native-permissions` is just tell us wether "LOCATION_ALWAYS" is "granted" or something else. Here we need to detect which service is enabled by user right now. Is there any method to do it?? – Archana Sharma Jan 24 '20 at 04:27
  • 1
    I want to get enabled option value by user. Any Suggestions?? – Archana Sharma Jan 24 '20 at 04:28
  • 1
    What does "granted" status means? It always return granted if user chooses any option except "never"?? I want to detect that user chooses "Always" or not? – Archana Sharma Jan 24 '20 at 06:51
  • did you find solution? – Khurshid Ansari Nov 11 '21 at 09:40
  • I saw google map also showing same popup and asking user to manually select alway from setting. – Khurshid Ansari Nov 11 '21 at 09:42