ios - Ionic 3 Platform Ready 仅在应用程序关闭或暂停后触发

标签 ios ionic-framework ionic3 hybrid-mobile-app ionic-native

我有一个使用地理定位的 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/

相关文章:

Android 应用程序强制横向视频,而应用程序是纵向的

ios - 快速将数据从 IOS 应用程序传输到 Watch 应用程序

iphone - 尝试在设备上运行测试时出现奇怪的错误

ios - 要求用户在电话设置中启用调用阻止和识别

ios - 如何在不使用GKPeerPickerController的情况下建立对等连接?

android - ionic - svg 不出现

cordova - 构建失败,无法读取未定义的属性 'reject'

android - 如何修复无法与 ionic 中的dex合并?

html - Ionic v3 对齐按钮和图标

javascript - npm/Frameworks/如何知道我应该使用哪个版本?