我有一个使用地理定位的 ionic 3 应用程序。该应用程序在 Android 上运行良好,但在 IOS 上有一个奇怪的行为。当我在 IOS 上运行该应用程序时,它会正常启动,但不会请求位置权限,直到我暂停或关闭该应用程序,从而导致该应用程序无法完全运行。我的地理位置 ID 包含在组件构造函数中的 platform.ready 函数中:
platform.ready().then(() => {
geolocation.getCurrentPosition().then(position => {
this.current_postion_lat = position.coords.latitude;
this.current_postion_long = position.coords.longitude;
console.log('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + position.timestamp + '\n');
console.log("Got to Location Provider Constructor");
const watch = geolocation.watchPosition().subscribe(pos => {
this.current_postion_lat = pos.coords.latitude;
this.current_postion_long = pos.coords.longitude;
console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude);
});
});
});
我的 ionic 信息:
@ionic/cli-utils:1.19.3 ionic ( ionic CLI):3.20.1
全局包:
cordova (Cordova CLI) : 8.0.0
本地包:
@ionic/app-scripts : 3.2.4
Cordova Platforms : android 8.0.0 browser 5.0.4 ios 5.1.1
Ionic Framework : ionic-angular 3.6.1
系统:
Android SDK Tools : 26.1.1
ios-sim : 8.0.2
Node : v10.16.3
npm : 4.1.2
OS : macOS
Xcode : Xcode 10.1 Build version 10B61
请帮忙。这导致我无法发布。
最佳答案
对于 iOS,您必须将以下配置添加到您的 configuration.xml 文件中。
<edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
<string>We use your location for full functionality of certain app features.</string>
</edit-config>
关于ios - Ionic 3 Platform Ready 仅在应用程序关闭或暂停后触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59711283/