BluetoothSerial插件未与离子的工作 [英] BluetoothSerial plugin is not working with ionic
问题描述
我试图蓝牙我离子的应用程序集成,以便它可以从蓝牙device.I尝试使用蓝牙插件接收数据,但我得到了一堆无论在PC和Android设备的错误。
我已经安装bluetoothserial使用下面的命令
科尔多瓦插件添加com.megster.cordova.bluetoothserial
块引用>%科尔多瓦插件
com.ionic.keyboard 1.0.4键盘
com.megster.cordova.bluetoothserial 0.4.3蓝牙串行
科尔多瓦 - 插件白名单1.0.1-DEV白名单
org.apache.cordova.console 0.2.13控制台
org.apache.cordova.device 0.3.0设备和这里是我的code
main.html中
< HTML和GT;
< HEAD>
<间的charset =UTF-8>
< META NAME =视口CONTENT =初始规模= 1,最大规模= 1,用户自可扩展=无,宽度=设备宽度>
<标题>< /标题><链接HREF =LIB /离子/ CSS / ionic.css的rel =stylesheet属性>
<链接HREF =CSS / style.css文件的rel =stylesheet属性>
<脚本SRC =LIB /离子/ JS / ionic.bundle.js>< / SCRIPT>
<脚本SRC =JS / NG-cordova.min.js>< / SCRIPT>
&所述; SCRIPT SRC =cordova.js>&下; /脚本>
&LT;脚本src=\"https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-resource.min.js\"></script>
&所述; SCRIPT SRC =https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js&GT;&下; /脚本&GT;
&所述; SCRIPT SRC =https://cdnjs.cloudflare.com/ajax/libs/ng-tags-input/2.3.0/ng-tags-input.min.js&GT; &LT; / SCRIPT&GT;
&LT;脚本SRC =JS / app.js&GT;&LT; / SCRIPT&GT;
&LT; /头&GT;app.js
angular.module('启动'['离子','ngCordova','ngRoute','ngTagsInput'])
.RUN(函数($ ionicPlatform){
$ ionicPlatform.ready(函数(){
//默认隐藏附件栏(删除此显示键盘上方的附件栏
//表单输入)
$ cordovaBluetoothSerial.isEnabled()。然后(
功能(){
$ cordovaDialogs.alert(蓝牙LE已启用,蓝牙LE,太棒了!);
},
功能(){
$ cordovaDialogs.alert(蓝牙LE不启用,蓝牙LE,哎呀!);
}
);
如果(window.cordova&安培;&安培; window.cordova.plugins.Keyboard){
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(真);
}
如果(window.StatusBar){
StatusBar.styleDefault();
}
});
})
.controller('datactr',['$范围,$ HTTP,$ cordovaBluetoothSerial',函数($范围,$ HTTP,$ cordovaBluetoothSerial){
的console.log($ cordovaBluetoothSerial.available());
}]);我收到以下错误:
类型错误:无法读取属性未定义的可用
未捕获的ReferenceError:未定义$ cordovaBluetoothSerial
块引用>谁能帮助?
解决方案使用$超时,这是为我工作。
.controller('BlueController',函数($ cordovaBluetoothSerial,$范围,$超时){...
$ scope.checkBT =功能(时间){
$超时(函数(){
$ cordovaBluetoothSerial.isEnabled(),然后(有趣,有趣)。
},时间);
};
$ scope.checkBT(750);I am trying to integrate bluetooth in my ionic app so that it can receive data from a bluetooth device.I tried to use the Bluetooth plugin but I get a bunch of errors both on PC and on android device. I have installed bluetoothserial using the following command
cordova plugin add com.megster.cordova.bluetoothserial
%cordova plugins com.ionic.keyboard 1.0.4 "Keyboard" com.megster.cordova.bluetoothserial 0.4.3 "Bluetooth Serial" cordova-plugin-whitelist 1.0.1-dev "Whitelist" org.apache.cordova.console 0.2.13 "Console" org.apache.cordova.device 0.3.0 "Device"
and here is my code
main.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> <link href="lib/ionic/css/ionic.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet"> <script src="lib/ionic/js/ionic.bundle.js"></script> <script src="js/ng-cordova.min.js"></script> <script src="cordova.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-resource.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ng-tags-input/2.3.0/ng-tags-input.min.js"> </script> <script src="js/app.js"></script> </head>
app.js
angular.module('starter' ['ionic','ngCordova','ngRoute','ngTagsInput']) .run(function($ionicPlatform) { $ionicPlatform.ready(function() { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) $cordovaBluetoothSerial.isEnabled().then( function() { $cordovaDialogs.alert("Bluetooth LE is enabled", "Bluetooth LE", "GREAT!"); }, function() { $cordovaDialogs.alert("Bluetooth LE is NOT enabled", "Bluetooth LE", "Oops!"); } ); if(window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); } if(window.StatusBar) { StatusBar.styleDefault(); } }); }) .controller('datactr',['$scope','$http' ,'$cordovaBluetoothSerial',function($scope,$http,$cordovaBluetoothSerial) { console.log($cordovaBluetoothSerial.available()); }]);
I get the following errors:
TypeError: Cannot read property 'available' of undefined
Uncaught ReferenceError: $cordovaBluetoothSerial is not defined
can anyone help?
解决方案Use $timeout, It's working for me.
.controller('BlueController',function ($cordovaBluetoothSerial,$scope,$timeout) {...
$scope.checkBT = function (time) { $timeout(function () { $cordovaBluetoothSerial.isEnabled().then(fun,fun); },time); }; $scope.checkBT(750);
这篇关于BluetoothSerial插件未与离子的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!