Setting NSLocationWhenInUseUsageDescription value when using cordova-plugin-geolocation

柔情痞子 提交于 2019-11-29 14:48:46

NEW ANSWER:

If using Cordova CLI 6.5.0 or newer and latest version of cordova-plugin-geolocation (>=3.0.0), you should use edit-config tag in the config.xml like this:

<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
    <string>your custom text here</string>
</edit-config>

OLD OUTDATED ANSWER: Fork the github plugin

change the NSLocationWhenInUseUsageDescription with the text you want

<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
    <string>your custom text here</string>
</config-file>

then remove the original geolocation plugin and install your fork with

cordova plugin add https://github.com/yourUsername/yourGeolocationFork.git

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:

cordova plugin add https://github.com/apache/cordova-plugin-geolocation#f9f7a23c57daad5514ce3d830a2defeb93ba3f78 --save --variable GEOLOCATION_USAGE_DESCRIPTION="Your text here"

The accepted answer is not working for me with Phonegap build. The following works for me :

<gap:config-file overwrite="true" parent="NSLocationWhenInUseUsageDescription" platform="ios">
    <string> your custom text here</string>
</gap:config-file>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!