fix(mp): 监听器改为 connection:true 后注册,修复 notifyBLECharacteristicValueChange:not init
根因日志:
SDK 数据事件: {errno:1500101, errMsg:"notifyBLECharacteristicValueChange:fail:not init"}
veepooWeiXinSDKNotifyMonitorValueChange 内部调用
wx.notifyBLECharacteristicValueChange,需要蓝牙适配器已初始化。
onLoad 时适配器未初始化 → 订阅失败 → 后续所有 BLE 数据丢失。
修正:从 onLoad 移除,改到 connection:true 回调中注册
(此时适配器已初始化、连接已建立、特征值已发现并订阅)。
This commit is contained in:
@@ -91,12 +91,13 @@ Page({
|
||||
wx.setNavigationBarTitle({ title: 'M2 手环测量' });
|
||||
this._updateSelectedDisplay('heart_rate');
|
||||
|
||||
// 在页面加载时一次性注册全局 SDK 监听器
|
||||
this._registerGlobalListeners();
|
||||
// 注意:不在 onLoad 注册 veepooWeiXinSDKNotifyMonitorValueChange!
|
||||
// 该函数内部会调用 wx.notifyBLECharacteristicValueChange,需要蓝牙适配器已初始化。
|
||||
// onLoad 时适配器未初始化 → 返回 "notifyBLECharacteristicValueChange:fail:not init"
|
||||
// 监听器改在 _doConnect 的 connection:true 回调中注册。
|
||||
|
||||
// 诊断
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 页面已加载,全局监听器已注册');
|
||||
console.log('[veepoo-native] 页面已加载');
|
||||
},
|
||||
|
||||
onUnload: function () {
|
||||
@@ -219,8 +220,14 @@ Page({
|
||||
self.setData({
|
||||
deviceId: device.deviceId || device.mac || '',
|
||||
});
|
||||
|
||||
// 关键:在连接就绪后注册数据监听器
|
||||
// veepooWeiXinSDKNotifyMonitorValueChange 内部会调用
|
||||
// wx.notifyBLECharacteristicValueChange,需要蓝牙适配器已初始化+已连接
|
||||
self._registerGlobalListeners();
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 连接就绪,500ms 后发送认证');
|
||||
console.log('[veepoo-native] 连接就绪,监听器已注册,500ms 后发送认证');
|
||||
|
||||
setTimeout(function () {
|
||||
// eslint-disable-next-line no-undef
|
||||
|
||||
Reference in New Issue
Block a user