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

Dmi*_*nko 5 cordova cordova-plugins

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

通常,要设置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>
Run Code Online (Sandbox Code Playgroud)

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

因此NSLocationWhenInUseUsageDescription,对于以项目重建持续存在的方式设置任何帮助都表示赞赏.

jce*_*ile 11

新答案:

如果使用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>
Run Code Online (Sandbox Code Playgroud)

旧的答案:分叉github插件

NSLocationWhenInUseUsageDescription用你想要的文字改变

<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
    <string>your custom text here</string>
</config-file>
Run Code Online (Sandbox Code Playgroud)

然后删除原始geolocation插件并安装你的fork

cordova plugin add https://github.com/yourUsername/yourGeolocationFork.git
Run Code Online (Sandbox Code Playgroud)

  • @Jobayer 不,在 config.xml 的根目录中或 iOS 平台标签内的任何位置,但在插件之外,因为即使您没有安装插件,它也会设置该值 (2认同)