Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova iOS location message

Tags:

ios

cordova

I use the plugin cordova-plugin-geolocation. My only issue is that the message prompt to allow location looks like this:

/var/container/bundle/application/xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx/my_project/www/index.html Would like to use your location.

Is there anyway to have something a little bit sexier, like

my_project would like to use your location

Cheers.

Added some code, for the non believers

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(){

    navigator.geolocation.getCurrentPosition(onLocationSuccess, onLocationError, {maximumAge:3000, timeout:2000, enableHighAccuracy:true});

    function onLocationSuccess(){

    }

    function onLocationError(){

    }
 }
like image 649
Eric Avatar asked Nov 25 '16 18:11

Eric


4 Answers

The solution has changed for cordova-plugin-geolocation: "4.0.0". This is what you need to add in your config.xml:

<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
    <string>need location access to find things nearby</string>
</edit-config>

For more information: https://github.com/apache/cordova-plugin-geolocation

like image 124
Stan Avatar answered Oct 20 '22 00:10

Stan


There are 3 possible reasons for displaying the path to the index.html instead of the name of your app:

  1. You have not installed the plugin (or it's not installed correctly)
  2. You are not waiting for the device ready event to call the plugin
  3. You have not linked the cordova.js file in the index.html

As you say that you have installed the plugin and you are using it on device ready event, then it must be that you have forgotten to link the cordova.js in the index.html or the plugin wasn't installed correctly. Check that you have the cordova.js linked and if you have it, remove the plugin and add it again, removing and re adding the iOS platform might help too

like image 42
jcesarmobile Avatar answered Oct 19 '22 23:10

jcesarmobile


From docs:

iOS Quirks

Since iOS 10 it's mandatory to add a NSLocationWhenInUseUsageDescription entry in the info.plist.

NSLocationWhenInUseUsageDescription describes the reason that the app accesses the user's location. When the system prompts the user to allow access, this string is displayed as part of the dialog box. To add this entry you can pass the variable GEOLOCATION_USAGE_DESCRIPTION on plugin install.

Example: cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="your usage message"

If you don't pass the variable, the plugin will add an empty string as value.

To solve your problem, try:

Uninstall the plugin:

cordova plugin remove cordova-plugin-geolocation

Reinstall with:

cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="my_project would like to use your location"
like image 36
Bruno Peres Avatar answered Oct 20 '22 00:10

Bruno Peres


It seems like the version 3.0.0 of cordova-plugin-geolocation ignores the install parameter

--variable GEOLOCATION_USAGE_DESCRIPTION=""

like Bruno Peres said above.

It works fine for me installing the 2.4.3 version.

like image 35
carlo318 Avatar answered Oct 20 '22 01:10

carlo318