我正在使用 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/