fix(mp): 数据监听器改回连接就绪后注册 + 增加轮询诊断日志
wx.onBLECharacteristicValueChange 只支持一个回调, SDK 合并连接函数可能内部也调用它,连接前注册会被覆盖。 改为 connection:true 回调后、认证前注册(对齐 SDK 文档顺序)。 增加每 500ms 轮询时打印 deviceChipStatus 实际值便于定位。
This commit is contained in:
@@ -174,18 +174,11 @@ Page({
|
||||
console.log('[veepoo-native] 连接设备:', device.deviceId || device.mac);
|
||||
var self = this;
|
||||
|
||||
// 关键修复:在连接前注册数据监听器
|
||||
// SDK 的 veepooWeiXinSDKNotifyMonitorValueChange 内部封装 wx.onBLECharacteristicValueChange
|
||||
// 必须在连接 + 订阅特征值之前注册,否则会丢失认证响应(type=1)
|
||||
self._registerListeners();
|
||||
|
||||
veepooBle.veepooWeiXinSDKBleConnectionServicesCharacteristicsNotifyManager(device, function (result) {
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 连接回调:', JSON.stringify(result));
|
||||
|
||||
// 只响应最终回调(connection:true),忽略中间阶段(services/characteristics/errno:0)
|
||||
// 连接回调会触发多次:createBLEConnection → services → characteristics → connection:true
|
||||
// 认证必须在特征值订阅完成后发送
|
||||
if (result.connection === true) {
|
||||
self._connected = true;
|
||||
self._connecting = false;
|
||||
@@ -193,7 +186,10 @@ Page({
|
||||
deviceId: device.deviceId || device.mac || '',
|
||||
});
|
||||
|
||||
// 连接成功后延迟 500ms 发送认证指令(等待特征值订阅就绪)
|
||||
// 按 SDK 文档顺序:连接就绪 → 注册数据监听器 → 延迟 → 认证
|
||||
// wx.onBLECharacteristicValueChange 只支持一个回调,连接后注册避免被 SDK 内部覆盖
|
||||
self._registerListeners();
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
setTimeout(function () {
|
||||
veepooFeature.veepooBlePasswordCheckManager();
|
||||
@@ -202,11 +198,13 @@ Page({
|
||||
console.log('[veepoo-native] 认证指令已发送');
|
||||
}, 500);
|
||||
|
||||
// 双重检测认证结果:事件监听器(type=1)+ Storage 轮询兜底
|
||||
// 双重检测:事件监听器(type=1)+ Storage 轮询兜底
|
||||
self._authTimer = setInterval(function () {
|
||||
try {
|
||||
// eslint-disable-next-line no-undef
|
||||
var status = wx.getStorageSync('deviceChipStatus');
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log('[veepoo-native] 轮询 deviceChipStatus=', status);
|
||||
if (status === 'successfulVerification' || status === 'passTheVerification') {
|
||||
clearInterval(self._authTimer);
|
||||
self._authTimer = null;
|
||||
|
||||
Reference in New Issue
Block a user