Fix Cordova Geolocation Ask for Location Message

How to remove ios geolocation auth request message on cordova

You need to install cordova-plugin-geolocation (cordova plugin add cordova-plugin-geolocation) then set your preferences in your config.xml, for iOS, such as

    <edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
<string>need to access your location for reasons</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSLocationAlwaysAndWhenInUseUsageDescription">
<string>need to access your location for reasons</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSLocationAlwaysUsageDescription">
<string>need to access your location for reasons</string>
</edit-config>

Of course edit

need to access your location for reasons

Cordova iOS location message

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

Location permission alert on iPhone with Cordova

Same as the "edit" in the original question, 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 as DaveAlden mentions in his answer 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.

Has anyone faced Geolocation permission alert for iOS showing twice issue along with bundle location?

I finally solved this with on device ready function loading to body tag

 function onDeviceReady(){
return navigator.geolocation.getCurrentPosition(initialize);
document.addEventListener("backbutton", onBackKeyDown, false);

}

function onLoad()
{
if (typeof navigator.device == "undefined"){
document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady();
}
}

<body onload="onLoad();">


Related Topics



Leave a reply



Submit