From e406ac46be4dc93b4c0f461da15040c914cf1174 Mon Sep 17 00:00:00 2001 From: wyf <494641114@qq.com> Date: Thu, 21 Aug 2025 17:22:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0ios=E8=93=9D=E7=89=99?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/mh_page/test/WebviewTestModel.dart | 62 +++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/lib/pages/mh_page/test/WebviewTestModel.dart b/lib/pages/mh_page/test/WebviewTestModel.dart index f64a0b0..9357c8c 100644 --- a/lib/pages/mh_page/test/WebviewTestModel.dart +++ b/lib/pages/mh_page/test/WebviewTestModel.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'dart:typed_data'; import 'package:EasyDartModule/EasyDartModule.dart' as edm; import 'package:easydevice/easydevice.dart'; @@ -17,6 +18,7 @@ import 'package:vbvs_app/controller/user_info_controller.dart'; import 'package:vbvs_app/model/WebSocketMessage.dart'; import 'package:vbvs_app/pages/main_bottom/component/main_page_b_bottom_change.dart'; import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart'; +import 'package:vbvs_app/pages/mh_page/device/mht_blueteeth_device_page.dart'; import 'package:vbvs_app/pages/mh_page/homepage/component/HomeDeviceStausWidget.dart'; import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart'; @@ -68,16 +70,60 @@ class WebviewTestController extends GetControllerEx { final devices = args1.devices as Map; final mac = args2 as String; - // 找出对应设备 - final device = devices[mac]; - - if (device != null) { - ef.log('Minibleapp connected: $mac -> $device'); + // Android: key 就是 mac,直接找 + if (devices.containsKey(mac)) { + final device = devices[mac]; + ef.log('Minibleapp connected(Android): $mac -> $device'); return device; - } else { - ef.log('Minibleapp connected: $mac not found in devices'); - return null; } + + // iOS: 遍历所有设备,解析 manufacturerData 拿真实 deviceId(mac) + for (final entry in devices.entries) { + final manufacturerData = entry.value.manufacturerData; + String? deviceId; + + if (manufacturerData != null) { + manufacturerData.forEach((key, data) { + if (data.isEmpty) return; + + if (key == 65517) { + List a = [0, 0, ...data]; + final d = {}; + advertisDataFormatter(a, d); + if (d['adData']?['deviceId'] != null) { + deviceId = d['adData']['deviceId']; + } + } else if (key == 11125 && data.length == 8) { + deviceId = ab2str(data.sublist(2, 8)).toUpperCase(); + } else if (data.length == 8 && + isQuanShiDevice(entry.value.name)) { + deviceId = ab2str(data.sublist(2, 8)).toUpperCase(); + } else if ((data.length == 4 || data.length == 6) && + isMHTSWES(entry.value.name)) { + List a; + if (data.length == 4) { + ByteData bd = ByteData(2); + bd.setUint16(0, key, Endian.little); + a = [bd.getUint8(0), bd.getUint8(1), ...data]; + } else { + a = [...data]; + } + deviceId = ab2str(a).toUpperCase(); + } + }); + } + + + final normalizedMac = mac.replaceAll(":", "").toUpperCase(); + + if (deviceId != null && + deviceId!.toUpperCase() == normalizedMac) { + return entry.value; // 返回匹配的设备 + } + } + + ef.log('Minibleapp connected: $mac not found in devices'); + return null; }, ); // ef.kvroot.devicelist.listen((x) {});