IONIC 2 的问题

ble trouble with IONIC 2

我正在使用 ionic 2 创建应用程序并尝试使用 ble-plugin。我运行安装:

$ cordova plugin add cordova-plugin-ble-central

然后在我页面的TS中写下如下内容:

从 'ionic-angular' 导入 {Page、Alert、NavController};

@Page({
  templateUrl: 'build/pages/hello-ionic/hello-ionic.html'
})

export class HelloIonicPage {

        constructor(public nav: NavController) { }
        bleScan() {
            ble.scan([], 5, function(device) {
                console.log(JSON.stringify(device));
            }, failure);
        }
}

但是,ble 未被识别,因此我的代码出现错误。我是否需要注入依赖性或其他东西,为什么这不起作用?

使用ble之前,您需要先导入它。

试试这个?我还在绊倒一个涉及 BLE API 使用的 ionic 2 项目,但我还没有开始做。 http://www.joshmorony.com/using-cordova-plugins-in-ionic-2-with-ionic-native/

您需要添加导入如下:

import {BLE} from 'ionic-native';

并像这样使用它:

 BLE.scan([], 5).subscribe(device => {
      console.log(JSON.stringify(device));
    }, error => {
      console.log(error);
    });

First add top your page in TS

import {BLE} from 'ionic-native'

Just use in your TS page

    this.platform.ready().then(() => {

        BLE.enable();

        BLE.startScan([]).subscribe(device => {

            console.log(JSON.stringify(device));              
        },
            err => {
                //this.message = "Error";
            });
    });