Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ionic 2中,我在BluetoothSerial.isEnabled和BluetoothSerial.list()时遇到此错误_Bluetooth_Ionic2_Bluetooth Lowenergy - Fatal编程技术网

在ionic 2中,我在BluetoothSerial.isEnabled和BluetoothSerial.list()时遇到此错误

在ionic 2中,我在BluetoothSerial.isEnabled和BluetoothSerial.list()时遇到此错误,bluetooth,ionic2,bluetooth-lowenergy,Bluetooth,Ionic2,Bluetooth Lowenergy,打字错误 类型“typeof BluetoothSerial”上不存在属性“isEnabled” BluetoothSerial.isEnabled().then((data)=> { 还有这里 BluetoothSerial.list().then((allDevices) => { 以上是我在ionic 2中运行时遇到的错误。 谢谢。我认为它不起作用,因为浏览器无法检测蓝牙设备。请尝试在实际设备上运行该应用程序。然后使用chrome://inspect 通过USB调试查看日志

打字错误 类型“typeof BluetoothSerial”上不存在属性“isEnabled”

BluetoothSerial.isEnabled().then((data)=> {
还有这里

BluetoothSerial.list().then((allDevices) => {
以上是我在ionic 2中运行时遇到的错误。
谢谢。

我认为它不起作用,因为浏览器无法检测蓝牙设备。请尝试在实际设备上运行该应用程序。然后使用chrome://inspect 通过USB调试查看日志

所以我编辑了你的代码和它的工作原理。就是这样。它显示配对设备,但未发现设备

import {Component} from '@angular/core';
import {AlertController, NavController} from 'ionic-angular';
import {BluetoothSerial} from '@ionic-native/bluetooth-serial';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  public deviceList:any;
  constructor(public navCtrl: NavController,
              private alertCtrl:AlertController,
              private bluetoothSerial: BluetoothSerial) {
    this.getAllBluetoothDevices();
  }

  // put BluetoothSerial inside a function, can't be called different
  getAllBluetoothDevices() {

    // async so keep everything in this method
    this.bluetoothSerial.isEnabled().then(data => {
      if(data){
        this.bluetoothSerial.list().then(allDevices=> {
          // set the list to returned value
          if(allDevices.length > 0){
            this.deviceList=allDevices;
          }else{
            let alert = this.alertCtrl.create({
              title: 'Bluetooth',
              subTitle: 'No devices found.',
              buttons: ['Dismiss']
            });
            alert.present();
          }
        });
      }
    }).catch(err=>{
      let alert = this.alertCtrl.create({
        title: 'Bluetooth',
        subTitle: 'Check your bluetooth connection.',
        buttons: ['Dismiss']
      });
      alert.present();
    });
  }

}

我以任何方式解决问题,但我没有得到上述错误, 但是现在我没有得到console.loglist

有人能说代码正在运行吗?? 因为我没有得到任何错误,但也没有得到控制台日志

import { Component } from '@angular/core';
import { BluetoothSerial } from '@ionic-native/bluetooth-serial';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

public working:string;
public var2: string ;
public lists = [];
public bluetoothSerial: BluetoothSerial;

constructor(public navCtrl: NavController ) {
let me = this;
   me.getAllBluetoothDevices();
}

// put BluetoothSerial inside a function, can't be called different
getAllBluetoothDevices(){
let me = this;

    // async so keep everything in this method
   me.bluetoothSerial.isEnabled().then((data)=> {
        // not sure of returning value, probably a boolean
        console.log("dont know what it returns"+data);

        // returns all the available devices, not just the unpaired ones
       me.bluetoothSerial.list().then((allDevices) => {
            // set the list to returned value
            me.lists = allDevices;
             console.log("lists");
             if(me.lists.length == 0){
               me.var2 = "could not find any bluetooth devices";
                console.log("lists");
            }


        });
    });
   }
}

你能通过ing将你的package.json添加到问题中吗?我现在更新我的问题,我尝试构建项目,但它无法构建项目,并显示错误,因为我提到我已经在android设备上运行了上述代码,并使用chrome://inspect 我可以查看配对设备的阵列我想在apk中运行上述代码,上面还说在android上检查你的蓝牙连接。让我再测试一次