【发布时间】:2016-06-10 09:22:25
【问题描述】:
我第一次使用 Ionic 插件。有一台 PaypalHere 平板电脑,我正在尝试连接到我的应用程序,该应用程序使用蓝牙。所以以后需要在某个地方输入一个Mac地址。但只需要先让蓝牙工作。
我已经使用“cordova plugin add cordova-plugin-bluetooth-serial”安装了蓝牙 https://github.com/don/BluetoothSerial
我最初安装了 npm inistall -g cordova,但现在看到有关 ngcordova 教程的参考资料?
谁能帮助我现在需要添加到我的 app.js 文件(控制器)以获得蓝牙正在工作并完全启用蓝牙的提示?
我假设我需要在控制器中注入服务,然后运行一些函数来执行检查。
这里有一个帖子,但似乎不完整 BluetoothSerial plugin is not working with ionic
这是我的 app.js 代码:
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tabs', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
.state('tabs.home', {
url: '/home',
views: {
'home-tab' : {
templateUrl: 'templates/home.html'
}
}
})
.state('tabs.list', {
url: '/list',
views: {
'list-tab' : {
templateUrl: 'templates/list.html',
controller: 'ListController'
}
}
})
.state('tabs.detail', {
url: '/list/:aId',
views: {
'list-tab' : {
templateUrl: 'templates/detail.html',
controller: 'ListController'
}
}
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/home');
})
.controller('ListController', ['$scope', '$http', '$state', function($scope, $http, $state) {
$http.get('js/data.json').success(function(data) {
$scope.orders = data;
$scope.whichorder = $state.params.aId;
});
}]);
我在 PC 上的 Chrome 浏览器中执行此操作
【问题讨论】:
-
好吧,首先,即使我通过命令行安装了蓝牙。看起来我也需要安装 ngCordova。所以我在这里做了这个pointdeveloper.com/what-is-ngcordova-how-to-use-it-with-ionic - 虽然仍然需要在这个 app.js 文件中检查蓝牙功能,也许在控制器上。
标签: angularjs cordova ionic-framework bluetooth