Cordova iOS 关于当前位置的通知

Cordova iOS Notification about current location

所以在任何人喊重复之前,我已经阅读了几个小时的东西我已经确保所有代码都在 document.addEventListener("deviceready" 并且仍然遇到这个问题我使用最新版本的 cordova 和地理定位插件cordova install cordova-plugin-geolocation

我已将 config.xml 设置为包含

<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
    <string>Allows events near you to be located.</string>
</edit-config>

我仔细检查了 {app_name}-Info.plist,它确实包含 NSLocationWhenInUseUsageDescription 的值,因此 config.xml 有效并且正在工作。

但是我仍然看到 '{app_name}.app/www/index.html' Would Like To Use Your Current Location 用户通知

我使用的代码是

var options = {maximumAge: 0, timeout: 10000, enableHighAccuracy:true};
document.addEventListener("deviceready", function(){
    navigator.geolocation.getCurrentPosition(function(e){
        var currLocBtn = $('<div id="currentLocBtn">Use Current Location</div>');
        currLocBtn.click(function(){
            $("#lat").val(e.coords.latitude);
            $("#lng").val(e.coords.longitude);
            $("#locInp").val("").attr("placeholder", "Current Location");
            $("#cordsText").val("Current Location");
            $("#cordsDisplay").text("Current Location");
        });
        $("#searchoverlay").prepend(currLocBtn);
    }, function(){}, options);
}, false);

如果我运行 navigator.geolocation.getCurrentPosition((e) => console.log(e), (e) => console.log(e)); 在我的应用程序的网络检查器控制台中,它执行相同的操作,就像 cordova 包装器不工作一样。

所以这显然是由于构建系统搞乱了 xcode 项目造成的。使用 prepare 和 build 命令,我们没有链接到 xcode 项目的插件来解决这个问题,我不得不使用

cordova platform remove ios
cordova platform add ios

这迫使它删除并重建 xcode 项目文件并解决了问题。