BluetoothSerial插件不适用于ionic
BluetoothSerial plugin is not working with ionic
我正在尝试将蓝牙集成到我的ionic应用程序中,以便它可以从蓝牙设备接收数据。我试着使用蓝牙插件,但我在PC和android设备上都遇到了一堆错误。我已经使用以下命令安装了bluetoothserial
cordova插件添加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"
这是我的代码
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());
}]);
我得到以下错误:
TypeError:无法读取未定义的属性"available"
未捕获引用错误:$cordovaBluetoothSerial未定义
有人能帮忙吗?
使用$timeout,它对我有效。
.controller('BlueController',function ($cordovaBluetoothSerial,$scope,$timeout) {...
$scope.checkBT = function (time) {
$timeout(function () {
$cordovaBluetoothSerial.isEnabled().then(fun,fun);
},time);
};
$scope.checkBT(750);
尝试
$ionicPlatform.ready(function() {
$cordovaBluetoothSerial.isEnabled().then(function(){
$scope.habilitado = true;
alert('Bluetooth habilitado');
},function(){
alert('Bluetooth nao habilitado');
});
});
这个问题或多或少与$cordovaBluetoothSerial在您尝试使用它时不可用有关。
此外,你需要确保你没有在浏览器上进行测试,因为它不起作用!在适当的Android或iOS设备上进行测试。
相关文章:
- JQueryhide()不适用于Mozzilla,但适用于Chrome
- PHP中的setcookie仅适用于localhost
- html5 drawImage适用于firefox,而不是chrome
- 提供“;onClick"适用于iPad(触摸屏)和桌面用户的默认功能
- jQuery表单验证适用于Mozilla和Internet Explorer,但不适用于Chrome或Safari
- ResolveUrl是否适用于././也
- Firebase updateChildValues适用于IOS,但不适用于Web和Android
- JavaScript警报适用于int,但不适用于string
- SQLite插件适用于Mac和Windows,但不适用于手机上的Safari
- Regex Replace仅适用于Last Match
- window.onload适用于aspx页面,但不适用于普通html
- Jquery Ajax POST不工作.适用于GET
- 画布上的自定义字体仅适用于safari
- Javascript仅适用于alert()和Debug模式
- JS适用于Firefox和Safari,但不适用于Chrome.此处'是我的网站
- Regex不适用于Firefox,但适用于Chrome
- 通过单击主菜单外部关闭子菜单'不适用于IE,但适用于Firefox&铬
- AngularJS$http.post没有'不适用于Chrome,仅适用于IE
- Javascript仅适用于jQuery mobile中的页面刷新
- 适用于iPad和iPhone的Ionic相同代码库