2017-05-30 11 views
0

Here screenshot of the error messageは、私はこのエラーを取得していながら、BluetoothSerial.isEnabledとBluetoothSerial.list()

活字体 プロパティ 'ISENABLEDは' 'typeof演算BluetoothSerial'

BluetoothSerial.isEnabled().then((data)=> { 

タイプ上に存在しないエラーとまた、ここで

BluetoothSerial.list().then((allDevices) => { 

上記は、私はありがとうイオン2 で、実行時に取得エラーです。

+0

[編集] ingであなたのpackage.jsonを追加できますか? –

+0

私は今質問を更新します –

答えて

1

ブラウザがBluetoothデバイスを検出できないため、実際のデバイスでアプリを実行しようとしているため、動作していないと思います。次に、USBデバッグを介してchrome:// inspectを使用してログを表示します。

私はあなたのコードとその作業を編集しました。これだよ。検出されなかったデバイスをペアにして表示します。

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(); 
    }); 
    } 

} 
+0

私はプロジェクトを構築しようとしますが、私が言及したようにプロジェクトをビルドすることはできません。 –

+0

あなたのコード全体を投稿できますか –

+0

私のコードを下に出しました。ありがとうございました:) –

0

私はこの問題を解決する任意の方法が、まだ私は 、上記のようにエラーになっていないのですが、今私ははconsole.log(「リスト」)を取得しておりません。

コードが実行されているかどうかは誰でも知っていますか? エラーは表示されませんが、コンソールログも取得されないためです。

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"); 
      } 


     }); 
    }); 
    } 
} 
関連する問題