请求始终权限在科尔多瓦地理位置

Request Always Permission in Cordova Geolocation

本文关键字:地理位置 权限 请求      更新时间:2023-09-26

看起来 PhoneGap 有一个配置.xml设置来更新项目中的 plist 键,以将地理位置插件的权限从"使用时"设置为"始终",如果我手动将项目的 .plist 文件的密钥设置为 NSLocationAlwaysUsageDescription 而不是插件的默认NSLocationWhenInUseUsageDescription它会设置正确的权限,但是我如何告诉插件请求 Always 权限而不必深入研究平台/ios/*.plist 文件?看起来插件代码有一个检查以查看要设置的权限,但我无法弄清楚如何请求它提示用户使用 JavaScript API 输入正确的权限。

请参阅:https://github.com/apache/cordova-plugin-geolocation/blob/master/src/ios/CDVLocation.m#L130

转到 platform/ios/ios.json查找以下内容:

 "*-Info.plist": {
                    "parents": {
                        "NSLocationWhenInUseUsageDescription": [
                            {
                                "xml": "<string />",
                                "count": 1
                            }
                        ]
                    }
                }

并将"NSLocationWhenInUseUsageDescription"替换为"NSLocationAlwaysUsageDescription"所以看起来像下面:

"*-Info.plist": {
            "parents": {
                "NSLocationAlwaysUsageDescription": [
                    {
                        "xml": "<string />",
                        "count": 1
                    }
                ]
            }
        }

运行"cordova build ios">