gpt4 book ai didi

javascript - BluetoothSerial 插件不适用于 ionic

转载 作者:可可西里 更新时间:2023-10-31 22:03:34 25 4
gpt4 key购买 nike

我正在尝试将蓝牙集成到我的 ionic 应用程序中,以便它可以从蓝牙设备接收数据。我尝试使用蓝牙插件,但我在 PC 和安卓设备上都遇到了一堆错误。我已经使用以下命令安装了 bluetoothserial

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"

这是我的代码

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>

应用程序.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: Cannot read property 'available' of undefined

Uncaught ReferenceError: $cordovaBluetoothSerial is not defined

谁能帮忙?

最佳答案

使用 $timeout,它对我有用。

.controller('BlueController',function ($cordovaBluetoothSerial,$scope,$timeout) {...

$scope.checkBT = function (time) {
$timeout(function () {
$cordovaBluetoothSerial.isEnabled().then(fun,fun);
},time);
};
$scope.checkBT(750);

关于javascript - BluetoothSerial 插件不适用于 ionic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30999759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com