Ionic 2 BLE断开回叫/订阅

时间:2017-07-22 23:23:18

标签: cordova ionic-framework bluetooth bluetooth-lowenergy subscribe

尝试订阅断开连接回调时出现此错误。

this.ble.disconnect(this.device_id).subscribe((data) => {
  console.log("disconnected good");
}, error => {
  console.log("disconnected bad");
});

我得到的错误就是这个

 Supplied parameters do not match any signature of call target.
 L116:  if (this.device_id) {
 L117:      this.ble.disconnect(this.device_id).subscribe((data) => {
 L118:              console.log("disconnected good");

2 个答案:

答案 0 :(得分:2)

disconnect - 函数返回Promise而不是Observabledocs)。

请改为尝试:

this.ble.disconnect(this.device_id)
.then(data => {
    console.log("disconnected good");
}
.catch(error => {
    console.log("disconnected bad");
});

答案 1 :(得分:0)

修正:

this.ble.disconnect(this.device_id).then(() => {
  console.log('Disconnected');
});