2024年4月2日
uniapp编译安卓App使用蓝牙api uni.notifyBLECharacteristicValueChange后续逻辑无返回问题处理
uniapp蓝牙模块存在安卓App在uni.notifyBLECharacteristicValueChange调用无返回的情况,官方并没有在文档中指出对应的解决方法,小程序没有任何问题,安卓App直接卡住无报错无返回,解决方案是在uni.notifyBLECharacteristicValueChange的success返回中的后续逻辑里添加1秒的延迟处理,微信小程序可以直接调用后续逻辑。
uni.notifyBLECharacteristicValueChange({ deviceId: that.deviceId, serviceId: that.serviceId, characteristicId: that.readCharacteristic, state: true, type: 'notification', success(res) { if (process.env.NODE_ENV == 'development') { console.log(res) } // #ifdef APP-PLUS setTimeout(function() { that.read() }, 1000); // #endif // #ifdef MP-WEIXIN that.read() // #endif },