From dc5d689d11561a6717064a25655606eb17ed0598 Mon Sep 17 00:00:00 2001 From: iven Date: Sat, 30 May 2026 22:43:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp):=20=E7=9B=91=E5=90=AC=E5=99=A8=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20connection:true=20=E5=90=8E=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20notifyBLECharacteristicValueChang?= =?UTF-8?q?e:not=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因日志: SDK 数据事件: {errno:1500101, errMsg:"notifyBLECharacteristicValueChange:fail:not init"} veepooWeiXinSDKNotifyMonitorValueChange 内部调用 wx.notifyBLECharacteristicValueChange,需要蓝牙适配器已初始化。 onLoad 时适配器未初始化 → 订阅失败 → 后续所有 BLE 数据丢失。 修正:从 onLoad 移除,改到 connection:true 回调中注册 (此时适配器已初始化、连接已建立、特征值已发现并订阅)。 --- apps/miniprogram/native/pkg-veepoo/index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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