接上一篇(原生微信小程序蓝牙开发(九))
当接收或发送完信息后,我们就需要断开蓝牙连接了
第十步:断开蓝牙设备(wx.closeBLEConnection)
断开与蓝牙低功耗设备的连接。
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
deviceId | string | 是 | 蓝牙设备 id | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
官方文档:wx.closeBLEConnection(Object object)
下面是我的代码:
// 断开蓝牙
closeBLE() {
const that = this;
wx.closeBLEConnection({
deviceId: that.data.deviceId,
success: function (res) {
// 断开蓝牙成功
},
fail: function (res) {
// 断开蓝牙失败
},
});
},
到此蓝牙开发就结束了,欢迎大家补充