IOS 11 上的 Cordova 插件地理位置超时
Cordova Plugin Geolocation Timeout on IOS 11
我访问了有关此问题的所有链接,none 帮助了我。
在 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);
});
}
我升级了所有插件和引擎,但错误仍然存在。
关注我当前的版本:
- 科尔多瓦 8.0.0;
- 科尔多瓦-ios 4.5.4;
- 科尔多瓦-android 7.0.0;
- cordova-plugin-geolocation 4.0.0.
经过艰苦的努力,我找到了解决办法。我在“/platform/ios/{project_name}/{project_name}-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>
我访问了有关此问题的所有链接,none 帮助了我。
在 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);
});
}
我升级了所有插件和引擎,但错误仍然存在。 关注我当前的版本:
- 科尔多瓦 8.0.0;
- 科尔多瓦-ios 4.5.4;
- 科尔多瓦-android 7.0.0;
- cordova-plugin-geolocation 4.0.0.
经过艰苦的努力,我找到了解决办法。我在“/platform/ios/{project_name}/{project_name}-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>