I'm building a mobile app using Cordova. I use cordova-plugin-geolocation
to get the user's current location. To customize the location permission request on iOS it's needed to set the NSLocationWhenInUseUsageDescription
plist value.
Generally, to set an iOS plist option it's needed to manually set the option value in the platforms/ios/<app-name>/<app-name>-Info.plist
. The problem is that on each build the cordova-plugin-geolocation
overwrites the custom value with it's default empty string.
A guess it has something to do with the following lines in the plugins/cordova-plugin-geolocation/plugin.xml
:
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
<string></string>
</config-file>
But if I try to set any value into that <string>
it is not respected, because it seems that the plugin.xml
is cached somewhere when the plugin is installed.
So any help with setting the NSLocationWhenInUseUsageDescription
in a way that persists over project rebuilds is appreciated.
The accepted answer is not working for me with Phonegap build. The following works for me :
NEW ANSWER:
If using Cordova CLI 6.5.0 or newer and latest version of
cordova-plugin-geolocation
(>=3.0.0), you should useedit-config
tag in theconfig.xml
like this:OLD OUTDATED ANSWER: Fork the github plugin
change the
NSLocationWhenInUseUsageDescription
with the text you wantthen remove the original geolocation plugin and install your fork with
A not yet released (to npm) version of the plugin supports this.
https://github.com/apache/cordova-plugin-geolocation/commit/f9f7a23c57daad5514ce3d830a2defeb93ba3f78
You can install it like this: