diff --git a/apps/miniprogram/native/pkg-veepoo/index.js b/apps/miniprogram/native/pkg-veepoo/index.js index de468a8..0938116 100644 --- a/apps/miniprogram/native/pkg-veepoo/index.js +++ b/apps/miniprogram/native/pkg-veepoo/index.js @@ -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