简体   繁体   中英

Ionic 3 Platform Ready fires only after app closes or is suspended

I have an ionic 3 app using geolocation. The app works fine on Android but I have a weird behaviour on IOS. When I run the app on IOS its starts normal but does not ask for location permission until I suspend or close the app thus causing the app not to be fully functional. My geolocation id wrapped in platform.ready function in my component constructor:

 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);
        });

      });
    });

My ionic info:

@ionic/cli-utils : 1.19.3 ionic (Ionic CLI) : 3.20.1

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@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

System:

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 

Please help. This has prevented me from releasing.

For iOS you have to add the below configuration to your configuration.xml file.

<edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
   <string>We use your location for full functionality of certain app features.</string>
</edit-config>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM