Search code examples
ioscordovaionic-frameworkcordova-pluginsionic-native

Ionic Native Diagnostic not Firing in iOS


I have an app that checks for location services for a store locator page - uses geolocation to get the nearest store to the user. Has worked fine up until a recent app update and then something broke. I've tried updating plugins, cordova, ionic, etc and just can't find the issue. Basically, the native Diagnostic plugin just doesn't fire, but I also don't get any thrown errors. Below is the function we've used to check for location services:

checkIfLocationPerms(){
let alert = this.alertCtrl.create({
  title: 'Error Loading Locations',
  subTitle:`You must allow geolocation permissions for this application before continuing. Please Change them in the settings of your device`,
  buttons: ['OK']
});
let timeoutFunct = setTimeout(()=>{
  this.goHome();
  alert.present();
}, 5000);
this.Diagnostic.isLocationAvailable().then(status=>{
  if(status == true){
    clearTimeout(timeoutFunct);
    this.loadMap();
  } else {
    timeoutFunct;
    this.Diagnostic.requestLocationAuthorization().then(data=>{
      if(data == this.Diagnostic.permissionStatus.GRANTED_WHEN_IN_USE ||
         data == this.Diagnostic.permissionStatus.GRANTED) {
        clearTimeout(timeoutFunct);
        this.loadMap()
      } else {
        clearTimeout(timeoutFunct);
        this.goHome();
        alert.present();
        return false;
      }
    }).catch(err=>{
      clearTimeout(timeoutFunct);
      this.goHome();
      alert.present();
    })
  }
}).catch(err=>{
  clearTimeout(timeoutFunct);
  this.goHome();
  alert.present();
})

}

Basically the clearTimeout function finishes before I get anything back from Diagnostic. If I don't call the clearTimeout function, I get nothing returned and no errors. Below is my Ionic Info:

Ionic:

   Ionic CLI          : 6.11.8 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.4

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : ios 5.1.1
   Cordova Plugins   : cordova-plugin-ionic-webview 4.2.1, (and 18 other plugins)

Utility:

   cordova-res : 0.15.1
   native-run  : 1.0.0

System:

   ios-deploy : 1.10.0
   ios-sim    : 6.1.3
   NodeJS     : v13.13.0 (/usr/local/Cellar/node/13.13.0_1/bin/node)
   npm        : 6.14.7
   OS         : macOS Catalina
   Xcode      : Xcode 11.7 Build version 11E801a

here's the versions of the pertinent plugins from package.json

"@ionic-native/diagnostic": "^5.28.0",

"@ionic-native/geolocation": "^4.18.0",

I can add that I don't get a response even if Locations Services is allowed. I don't see a way to allow the app to have access to Location Services either. I just don't know where to go from here, I've been fighting this for a week trying to figure it out. Anyone have any suggestions?


Solution

  • The only was I was able to get the correct permissions pop up was to update the Diagnostic plugin. I created a test application with all latest versions of Ionic, Diagnostic etc, and that worked properly.