Diagnostic Plugin not working


#1

Has anybody played around with the diagnostic plugin? I want to do a simple isLocationEnabled check and then switch it on if it is disable and enable the app to access the location services.

I’ve installed the plugin :
$ ionic plugin add cordova.plugins.diagnostic
$ npm install --save @ionic-native/diagnostic

Code usage in home.ts :

import {Component} from “@angular/core”;
import {App, NavController, AlertController} from “ionic-angular”;
import {ViewChild} from ‘@angular/core’;
import {StatusBar} from ‘ionic-native’;
import { Geolocation } from ‘@ionic-native/geolocation’;
import {Platform} from ‘ionic-angular’;
import { Diagnostic } from ‘@ionic-native/diagnostic’;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {
public locationSupported:boolean;

constructor(public app: App,
public diagnostic: Diagnostic,
public platform: Platform,
public nav: NavController) {

// let successCallback = (isAvailable) => { alert('Is available? ’ + isAvailable); };
// let errorCallback = (e) => console.error(e);
// this.diagnostic.isLocationEnabled().then(successCallback).catch(errorCallback);

platform.ready().then(() => {
this.diagnostic.isLocationEnabled().then((res) => {
alert(‘diagnostic result’+ res);
this.locationSupported = res;
}).catch((err) => {
alert(‘got an error using diagnostic’ + err);
//console.dir(err);
});

});

but when I run : ionic run android
[10:58:51] transpile started …
[10:58:56] typescript: plugins/cordova.plugins.diagnostic/cordova.plugins.diagnostic.d.ts, line: 6
Cannot find type definition file for ‘cordova’.
[10:58:56] transpile failed
L5: * “Dangerous” permissions that need to be requested at run-time (Android 6.0/API 23 and above)
L6: * See http://developer.android.com/guide/topics/security/permissions.html#perm-groups
L7: * @type {Object}[10:58:56] ionic-app-script task: “build”
[10:58:56] TypeError: error.message.indexOf is not a function

When I remove the diagnostic plugin, it builds properly but then I get an alert message saying that the corresponding plugin was not installed.

Any thoughts?


#2

cordova plugin add cordova.plugins.diagnostic
puts in version 3.4.2
cordova.plugins.diagnostic 3.4.2 “Diagnostic”

Workaround :
ionic plugin remove cordova.plugins.diagnostic
cordova plugin add cordova.plugins.diagnostic.api-22


#3

How to use isLocationAvailable() or getLocationAuthorizationStatus() ?

platform.ready().then(() => {
this.diagnostic.isLocationEnabled().then((res) => {
alert('Is Location Enabled? '+ res);
this.locationSupported = res;
if (this.locationSupported == true)
{
this.diagnostic.getLocationAuthorizationStatus().then ((status) => {alert(status);}).catch((error)=> {alert(error);})
// this.diagnostic.isLocationAvailable().then((authorized) => {
// alert (‘Is app authorized to use Location?’ + authorized)
// this.appAuthorized = authorized; }).catch((error) => {
// alert(error);
// })
}
}).catch((err) => {
alert('Location Enabled Error: ’ + err);
//console.dir(err);
});

});

Getting alert error :


#4

And if about API-23, in case runtime permissions