cordova - 使用 cordova-plugin-geolocation 时设置 NSLocationWhenInUseUsageDescription 值

标签 cordova cordova-plugins

我正在使用 Cordova 构建移动应用程序。我用cordova-plugin-geolocation获取用户的当前位置。要在 iOS 上自定义位置权限请求,需要设置 NSLocationWhenInUseUsageDescription plist 值。

一般来说,要设置 iOS plist 选项,需要手动设置 platforms/ios/<app-name>/<app-name>-Info.plist 中的选项值。 。问题是在每个构建上 cordova-plugin-geolocation用默认的空字符串覆盖自定义值。

猜测它与 plugins/cordova-plugin-geolocation/plugin.xml 中的以下几行有关:

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

但是如果我尝试在 <string> 中设置任何值它不受尊重,因为似乎 plugin.xml安装插件时缓存在某处。

因此,有关设置 NSLocationWhenInUseUsageDescription 的任何帮助以一种在项目重建过程中持续存在的方式受到赞赏。

最佳答案

新答案:

如果使用 Cordova CLI 6.5.0 或更新版本的 cordova-plugin-geolocation (>=3.0.0),您应该使用 edit-config 标签在 config.xml 中,如下所示:

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

过时的答案: fork github 插件

NSLocationWhenInUseUsageDescription 更改为您想要的文本

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

然后删除原始的地理定位插件并安装您的分支

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

关于cordova - 使用 cordova-plugin-geolocation 时设置 NSLocationWhenInUseUsageDescription 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33637591/

相关文章:

cordova - iOS IAP cordova-plugin-inapppurchase

javascript - cordova inappBrowser 插件将用户名和密码传递给 URL

iphone - iPhone 的 PhoneGap 数据库应用有什么要求?

ios - 为什么电话:* links don't work on ios?

cordova - 如何在ionic中为https请求添加android ssl证书?

javascript - Android 浏览器中某些键没有按键事件

cordova - Ionic cordova 文件传输插件无法通过 HTTPS 在 android 中下载文件

android - Cordova android 插件中的 onRequestPermissionsResult

ios - iOS 应用程序上带有 PhoneGap 的 native 选项卡栏

javascript - 获取设备电话号码的可靠方法