蓝牙小程序后台运行无法下发指令
发布于 5 年前 作者 li55 18615 次浏览 来自 问答

蓝牙倒计时小程序,按了右上角和HOME键后台运行,然后锁屏 调试时可以看到计时是正常的,就是结束的时候指令不下发了,只有再次进入小程序时才会下发。这是什么原因?

1 回复

that.data.setInter = setInterval(function () {        time --;        minute =  parseInt(time/60);        second = time%60;        that.setData({minute : minute});        that.setData({second :second});        console.log(time);        if(time == 0){        clearInterval(that.data.setInter)              var param = 0x01;        that.setData({ ‘send[0]’: param });        if (that.data.write_id) {          dataView.setUint8(0, “0x” + send[0])          // that.setData({‘buffer’ : send[0]});          console.log(send);          console.log(“endtime”);          wx.writeBLECharacteristicValue({            // 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取            deviceId: that.data.deviceId,            // 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取            serviceId: that.data.serviceId,            // 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取            characteristicId: that.data.write_id,            // 这里的value是ArrayBuffer类型            value: buffer,                                    success: function (res) {              console.log(send);            },            fail: function (res) {              console.log(res)            },          })        }       }      }        , 1000);

回到顶部