首页 文章

IOS 11上的Cordova插件地理位置超时

提问于
浏览
1

我访问了有关此问题的所有链接,没有人帮助过我 .

当IOS上的“cordova-plugin-geolocation”执行方法“getCurrentLocation”时,我总是得到错误代码3(超时) .

按照我的代码:

getCurrentPosition() {
 return new Promise(function (resolve, reject) {
  document.addEventListener("deviceready", function(){
    navigator.geolocation.getCurrentPosition((position) => {
      resolve(position);
    }, (error) => {
      reject(error);
    }, {
      timeout: 10000
    });
  }, false);
 });
}

我升级了所有插件和引擎,错误仍然存在 . 关注我当前的版本:

  • cordova 8.0.0;

  • cordova-ios 4.5.4;

  • cordova-android 7.0.0;

  • cordova-plugin-geolocation 4.0.0 .

1 回答

  • 1

    辛苦工作后,我找到了修复 . 我在“/platform/ios//-Info.plist”中添加了以下键:

    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>My app requires constant access to your location, even when the screen is off.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>My app requires constant access to your location, even when the screen is off.</string>
    

相关问题