5

Does anyone have experience using cordova, html and know how to fix this geolocation message issue for iOS? I just want the message to say the app name followed by the line, "would like to use your current location."

Current Geolocation Message:

///Users/kklsndksjladn/Library/Developer/CoreSimulator/Devices/FAF7EE4C-40BA-430A-80D5-5C84B07D970D/data/Containers/Bundle/Application/DAE305B6-C6DD-438B-B4D7-9B183A8B2D97/HelpME.app/www/index.html

I've tried various solutions from stack overflow and other websites. I implemented the navigator.geolocation.getCurrentPosition(onSuccess, onError); code, included my cordova.js file in every html page, made sure <script> src=cordova.js</script> appears first in my index.html page, included the geolocation tag in my config.xml file and tried playing around with my plist. Someone please help!!!!

-Thanks

AtanuCSE
  • 8,832
  • 14
  • 74
  • 112
pavbagel
  • 611
  • 2
  • 6
  • 17

2 Answers2

9

In addition to the answer from DaveAlden, I had to remove the old version of the geolocation plugin and add the new one. Then I had to remove/add the Cordova iOS platform. Only then could I add NSLocationWhenInUseUsageDescription to the .plist file with success.

First, remove/add the geolocation plugin:

cordova plugin rm org.apache.cordova.geolocation
cordova plugin add org.apache.cordova.geolocation

Second, remove/add the iOS platform:

cordova platform rm ios
cordova platform add ios

Last, add NSLocationWhenInUseUsageDescription to the .plist. Open /platforms/ios/{project}/{project}-Info.plist and add the following:

<key>NSLocationWhenInUseUsageDescription</key>
<string>[App Name] would like to access your location when running and displayed.</string>

See this iOS Developer Library link for detailed information regarding NSLocationWhenInUseUsageDescription versus NSLocationAlwaysUsageDescription versus NSLocationUsageDescription.

Location permission alert on iPhone with Cordova is a possible duplicate.

Community
  • 1
  • 1
trailing slash
  • 881
  • 11
  • 13
2

To customise the iOS location permission request message, you need to add a property to your project's .plist.

If your app requests permission to use location in the background, you want the following key (set the string value to anything you like):

<key>NSLocationAlwaysUsageDescription</key>
<string>My app requires constant access to your location, even when the screen is off.</string>

If your app only uses location while in the foreground, then add the following key:

<key>NSLocationWhenInUseUsageDescription</key>
<string>My app requires access to your location when the screen is on and the app is displayed.</string>
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • It works in iOS 8 (I'm using it my own [Cordova-powered geolocation app](https://itunes.apple.com/us/app/iwalk-north-cornwall/id739048330?ls=1&mt=8)). If you're testing with an older version of iOS, you need to use `NSLocationUsageDescription` - [see here](https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW18) – DaveAlden Mar 07 '15 at 17:34