Add Cordova diagnostic plugin in ionic?
I am new to ionic and I want to use the Corodova Diagnostic plugin in my ionic project. I don't know how to use ionic plugins. I added this plugin using this command.
$ cordova plugin add cordova.plugins.diagnostic
I can see this plugin on my list using
$ cordova plugins ls
now i have a separate controller file, i post his code here, when i try to use this, it gives error, cordova
angular.module('timetools_controllers', ['ui.utils', 'ionic','cordovaGeolocationModule'])
.controller('TimetoolsCtrl', ['$scope', '$http', '$localstorage', '$ionicPopup', function ($scope, $http, $localstorage, $ionicPopup) {
/*=================================================================================*/
// ABFRAGE OB TRACK & SHARE AKTIV IST
/*=================================================================================*/
var fdappAuth = $localstorage.getObject('fdappAuth');
$http({
method: 'GET',
url: 'http://app.flugdeck.com/options.php?apikey=7ksmewzSUd2asSA0384cosb!2w3SloE&do=get&optid=110&userId=' + fdappAuth.fdappUserId + '&userPwHash=' + fdappAuth.fdappUserPw,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
.success(function (data, status) {
// Verarbeitet die Daten und setzt diese zur Anzeige in die scopes
console.log("Optionsabfrage fΓΌr Track & Share lΓ€uft");
$scope.optentry = data[0];
$scope.optentry.opt_110 = data[0].opt_110;
if ($scope.optentry.opt_110 == 1) {
$scope.isTrackShareActive = "Tracking ";
$scope.cssClass = "Tracking";
} else {
$scope.isTrackShareActive = "Tracking ";
$scope.cssClass = "Tracking";
}
});
$scope.saveOffBlockTime = function () {
var datum = new Date();
console.log("Datums-String: " + datum);
// Erstelle das Datum und Poste das
if ($scope.OffBlockRunAlready === true) {
} else {
// Setzt das Datum
$scope.OffBlockTime = datum;
$scope.OffBlockRunAlready = true;
if ($scope.optentry.opt_110 == 1) {
/***********************/
// GPS TEST CODE CORDOVA
/***********************/
alert("GPS TEST");
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
console.log("Location is " + (enabled ? "enabled" : "disabled"));
}, function(error){
console.error("The following error occurred: "+error);
});
}
}
}; // saveOffBlockTime
}]) ;// Ende .controller('TimetoolsCtrl'...
but it gives the following error in the console.
ReferenceError: cordova is not defined
Can anyone help me?
my Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- build:css dist_css/styles.css -->
<link href="css/ionic.app.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- endbuild -->
<script src="http://maps.google.com/maps/api/js"></script>
<!-- build:js dist_js/modules.js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/underscore/underscore-min.js"></script>
<script src="lib/ngmap/build/scripts/ng-map.min.js"></script>
<script src="lib/moment/min/moment.min.js"></script>
<script src="lib/angular-moment/angular-moment.min.js"></script>
<script src="lib/angular-md5/angular-md5.min.js"></script>
<script src="lib/angular-base64/angular-base64.min.js"></script>
<script src="lib/angular-cordova-geolocation/cordovaGeolocationModule.js"> </script>
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<!-- endbuild -->
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- build:js dist_js/app.js -->
<script src="dist/dist_js/app/app.js"></script>
<script src="dist/dist_js/app/directives.js"></script>
<script src="dist/dist_js/app/controllers.js"></script>
<script src="dist/dist_js/app/templates.js"></script>
<script src="dist/dist_js/app/services.js"></script>
<script src="dist/dist_js/app/config.js"></script>
<script src="dist/dist_js/app/filters.js"></script>
<script src="js/mymodules.js"></script>
<script src="lib/ui-utils.min.js"></script>
<script src="js/controller_flightlog.js"></script>
<script src="js/controller_timetools.js"></script>
<script src="js/controller_infotools.js"></script>
<script src="dist/dist_js/app/factories.js"></script>
<!-- endbuild -->
</head>
<body ng-app="your_app_name">
<ion-nav-view></ion-nav-view>
</body>
</html>
source to share
the Github page for this plugin:
This iOS and Android Cordova / Phonegap plugin is used to check the status of the following device settings.
The plugin is specially designed to report the state of the device's own settings on Android and iOS platforms .
Hence, it does not support the browser platform and launching it on this will result in the observed error.
source to share
One thing to keep in mind when testing ngCordova plugins in your browser with $ ionic serve
is that it often results in cordova being undefined .
Most ngCordova plugins will not work in a web browser because they use their own device code.
Could you try to emulate your application? Check if it works? (You might want to change this console.log () to something else so you can see if it works in your emulator. For example, print $ scope.)
Example: $ ionic emulate ios
or $ ionic emulate android
.
source to share