在 Ionic 中添加 Cordova 诊断插件?
Add Cordova Diagnostic Plugin in Ionic?
我是 ionic 的新手,我想在我的 ionic 项目中使用 Corodova 诊断插件。我不知道如何在离子中使用插件。我已经使用这个命令添加了这个插件。
$ cordova plugin add cordova.plugins.diagnostic
我可以使用
在我的列表中看到这个插件
$ cordova plugins ls
现在我有一个单独的控制器文件,我 post 它的代码在这里,当我尝试使用它时,它给出错误,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'...
但它在控制台中给出以下错误。
ReferenceError: cordova is not defined
有人可以帮我吗?
我的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>
通过 $ ionic serve
在浏览器中测试 ngCordova 插件时要记住的一件事是,它通常会导致 cordova is not defined.
大多数 ngCordova 插件无法在 Web 浏览器中运行,因为它们使用本机设备代码。
能否尝试模拟您的应用并检查它是否有效? (您可能想将 console.log() 更改为其他内容,以便您可以查看它是否适用于您的模拟器。例如打印 $scope。)
示例:$ ionic emulate ios
或 $ ionic emulate android
。
此插件的 Github page 声明:
This Cordova/Phonegap plugin for iOS and Android is used to check the state of the following device settings
该插件专门用于在 Android 和 iOS 上报告本机设备设置的状态平台。
因此,它不支持浏览器平台,运行它会导致观察到的错误。
我是 ionic 的新手,我想在我的 ionic 项目中使用 Corodova 诊断插件。我不知道如何在离子中使用插件。我已经使用这个命令添加了这个插件。
$ cordova plugin add cordova.plugins.diagnostic
我可以使用
在我的列表中看到这个插件 $ cordova plugins ls
现在我有一个单独的控制器文件,我 post 它的代码在这里,当我尝试使用它时,它给出错误,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'...
但它在控制台中给出以下错误。
ReferenceError: cordova is not defined
有人可以帮我吗?
我的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>
通过 $ ionic serve
在浏览器中测试 ngCordova 插件时要记住的一件事是,它通常会导致 cordova is not defined.
大多数 ngCordova 插件无法在 Web 浏览器中运行,因为它们使用本机设备代码。
能否尝试模拟您的应用并检查它是否有效? (您可能想将 console.log() 更改为其他内容,以便您可以查看它是否适用于您的模拟器。例如打印 $scope。)
示例:$ ionic emulate ios
或 $ ionic emulate android
。
此插件的 Github page 声明:
This Cordova/Phonegap plugin for iOS and Android is used to check the state of the following device settings
该插件专门用于在 Android 和 iOS 上报告本机设备设置的状态平台。
因此,它不支持浏览器平台,运行它会导致观察到的错误。