2

I am developing an app with Cordova for iOS which includes geolocation functionalities (I use the official plugin https://github.com/apache/cordova-plugin-geolocation). I saw in options of my app that location access can be either set as "Never" or "While Using the App". However some other apps may also the option "Always" as shown in the attached screenshot. I would like to know whether it is possible to also have the option "Always" for Cordova-based applications.

enter image description here

Thanks!

Pierre
  • 1,044
  • 15
  • 27

3 Answers3

2

I was using both NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription in my company's Cordova app and it was working. Then, in late 2017, it stopped.

The fix for me has been to add also NSLocationAlwaysAndWhenInUseUsageDescription.

More broadly speaking, note that you need to have a plugin allowing to track location in background as well as make sure that the necessary background mode option is enabled in XCode. We use the following plugin to do the job: https://www.npmjs.com/package/cordova-plugin-lents-background-geolocation

This type of plugin is necessary as iOS stops execution of scripts for apps roughly 3 minutes after the display is turned off, regardless of the app foreground/background condition when the display was turned off. This prevents any JavaScript code to run and therefore any GPS tracking based on setInterval or setTimeout will stop working.

1

I guess "NSLocationAlwaysUsageDescription" key is the one which you are looking for. Check out this link which details the settings to be done in cordova based applications to have constant location access.

Community
  • 1
  • 1
Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • Hello, thanks for your answer but there is a misunderstanding. I want to have the option 'Always', I do not want to modify the text below the 3 options. – Pierre Apr 29 '16 at 08:50
  • @Pierre what do you mean by text below 3 options? this is what u look for i guess - NSLocationAlwaysUsageDescription My app requires constant access to your location, even when the screen is off. – Gandhi Apr 29 '16 at 10:02
  • I updated my picture in order order be to more clear – Pierre Apr 30 '16 at 02:06
1

I'm using Ionic 2 and had to add the following to my App-Info.plist file. Even though cordova inserts 'NSLocationAlwaysUsageDescription' and 'NSLocationWhenInUseUsageDescription' keys. This only gave a 'Never' and 'While Using App' option on launch. Xcode suggested using the option below and that worked for me.

        <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
        <string>This app requires background location tracking</string>