【问题标题】:Ionic 3 Platform Ready fires only after app closes or is suspendedIonic 3 Platform Ready 仅在应用程序关闭或暂停后触发
【发布时间】:2020-04-29 20:25:51
【问题描述】:

我有一个使用地理定位的 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/cli-utils:1.19.3 离子(离子 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 ionic-framework ionic3 hybrid-mobile-app ionic-native


    【解决方案1】:

    对于 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>
    

    【讨论】:

    • 我之前试过了。不能解决问题。仍然必须关闭或暂停平台的应用程序。准备触发。根据需要弹出权限弹出窗口,而不是在初始安装时
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 2021-01-05
    • 2018-04-12
    • 1970-01-01
    相关资源
    最近更新 更多