Geolocation on iOS time out issue

Hi all,

I’ve recently upgraded Ionic from 2 to 5 and for some reason the Geolocation plugin now always produces in a GPS time out using watchPosition on iOS, however, it works without issue on Android. It has been tested on 3 different iOS devices and none work.

var watchOptions = {
              timeout: 10000,
              maximumAge: 3600,
              enableHighAccuracy: highAccuracy 
            };
this.geoWatch = this.geolocation.watchPosition(watchOptions).subscribe((data) => {
                //console.log(data);
                if ('coords' in data) {
                  if (this.refreshStarted != true) {
                    this.refreshStarted = true;
                    this.processPing(data.coords);
                    this.updateStatus.next('done');
                  }
                } else if (data['message'] == 'Position retrieval timed out.') {
                  this.refreshStarted = false;
                  console.log('GPS timed out.');
                  this.stopLocationWatch();
                  this.startLocationWatch();
                  if (lastData) {
                    this.processPing(lastData);
                  }
                } else {
                  console.log('Warning: empty GPS ping.');
                  // console.log(JSON.stringify(data, null, 4));
                  this.refreshStarted = false;
                }
              }, (error) => {
                console.log(error);
                console.log('GPS timed out.');
                this.refreshStarted = false;
                if (this.usingCache == false) {
                  this.updateStatus.next('error-gps');
                }
              });

I’ve tried or ensured:

  1. All the correct parts of entered in Info.plist in the config file,
  2. I’ve tried deleting platforms and the plugin and re-building,
  3. Geolocation is added correctly to app.module.ts.
  4. Versions 5.28.0, 5.30.0 and 5.31.1.
  5. I’ve been searching for 4 days now and nothing has worked!
  6. Changing the distance filter in the plugin file CDVLocation.m as suggested by a few different posts on SO.
    One of the users is testing the app in the field travelling over 100m between locations so it doesn’t appear to be the issue with the iOS distance filter. As it works without issue on Android, the problem surely isn’t with the code. It seems to be somewhere between the Geolocation plugin and iOS’s GPS access.

Ionic Plugins:

        "@ionic-native/android-permissions": "^5.31.1",
        "@ionic-native/app-minimize": "^5.31.1",
        "@ionic-native/app-preferences": "^5.31.1",
        "@ionic-native/app-version": "^5.30.0",
        "@ionic-native/camera": "^5.30.0",
        "@ionic-native/core": "^5.31.1",
        "@ionic-native/diagnostic": "^5.30.0",
        "@ionic-native/file": "^5.30.0",
        "@ionic-native/file-transfer": "^5.30.0",
        "@ionic-native/geolocation": "^5.28.0",
        "@ionic-native/globalization": "^5.30.0",
        "@ionic-native/google-maps": "^5.27.0-beta-20200630",
        "@ionic-native/in-app-browser": "^5.30.0",
        "@ionic-native/keyboard": "^5.30.0",
        "@ionic-native/media": "^5.30.0",
        "@ionic-native/native-audio": "^5.30.0",
        "@ionic-native/native-storage": "^5.30.0",
        "@ionic-native/network": "^5.30.0",
        "@ionic-native/photo-viewer": "^5.30.0",
        "@ionic-native/screen-orientation": "^5.30.0",
        "@ionic-native/splash-screen": "^5.30.0",
        "@ionic-native/status-bar": "^5.30.0",
        "@ionic/angular": "^5.5.4",
        "@ionic/angular-toolkit": "^2.3.3",
        "@ionic/cli": "^6.12.1",
        "@ionic/storage": "^2.3.0",

Ionic Info:

Ionic:

   Ionic CLI                     : 6.11.12 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.4
   @angular-devkit/build-angular : 0.901.9
   @angular-devkit/schematics    : 11.1.3
   @angular/cli                  : 9.1.13
   @ionic/angular-toolkit        : 2.3.3

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.0.0, ios 6.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 29 other plugins)

Utility:

   cordova-res (update available: 0.15.3) : 0.15.1
   native-run (update available: 1.3.0)   : 1.2.2

System:

   Android SDK Tools : 26.1.1 (/Users/mwm/Library/Android/sdk)
   ios-deploy        : 1.11.1
   ios-sim           : 8.0.2
   NodeJS            : v10.22.1 (/usr/local/bin/node)
   npm               : 6.14.6
   OS                : macOS Big Sur
   Xcode             : Xcode 12.4 Build version 12D4e

Any advice would be greatly appreciated.

Thanks.

I’ve just tried to create a blank project with effectively only the Geolocation plugin and the same thing happens.

If anyone else has this issue, I’ve fixed it following the top answer of this post.