Getting location of iOS devices is inconsistent

I haven’t not been able to find an example of how to use cordova.plugins.diagnostic.requestLocationAuthorization in an Ionic 4 app.

Meaning, how to install the plugin and the import statement. I’ve created an Ionic 4 social media app and I’d like to prompt users for access to device location. It’s working fine in Android but iOS is not consistent. It will sometimes get the device location while testing on a real device and sometimes when I uninstall and redeploy it won’t. It just seems random at this point whether or not it retrieves and saves the device location to the backend for iOS devices. So I’d like to prompt users if I query the backend and don’t have their device location.

Any help would be greatly appreciated.

` this.platform.ready().then(() => {
firebase.auth().onAuthStateChanged(user => {
if (!user) {
this.router.navigateByUrl(‘login’);
this.statusBar.styleDefault();
this.splashScreen.hide();
} else {
cordova.plugins.diagnostic.requestLocationAuthorization((status) => {
console.log(status);
}, (error) => {
console.error(error);
}, cordova.plugins.diagnostic.locationAuthorizationMode.ALWAYS);
this.diagnostic.getLocationAuthorizationStatus()
.then((status) => {
if ((status === undefined) || (status === null)) {
this.diagnostic.requestLocationAuthorization();
}
console.log(‘auth stat’, status);
})
.catch((error) => {
console.log(error);
});
this.router.navigateByUrl(‘tabs/profile’);
this.statusBar.styleDefault();
this.splashScreen.hide();
}``
type or paste code here


Again I'm using: Ionic -v 5.4.13

9.0.0 (cordova-lib@9.0.1)

I can actually use this.diagnostic.getLocationAuthorizationStatus() to get the autorization status from iOS. But I need a way to prompt users in case it's not activated.



ERROR in src/app/app.component.ts:37:11 - error TS2304: Cannot find name ‘cordova’.

37 cordova.plugins.diagnostic.requestLocationAuthorization((status) => {
~~~~~~~
src/app/app.component.ts:41:12 - error TS2304: Cannot find name ‘cordova’.

41 }, cordova.plugins.diagnostic.locationAuthorizationMode.ALWAYS);
~~~~~~~

[ERROR] An error occurred while running subprocess ng.