fix(connectDevice): 修复跨平台蓝牙设备连接逻辑
适配iOS和Android不同的蓝牙地址规则,通过有效地址匹配设备后再发起连接
This commit is contained in:
parent
00baf6574a
commit
1e1fd209f9
@ -95,7 +95,23 @@ public class ConnectDevicePageCtrl : MonoBehaviour
|
||||
}
|
||||
}
|
||||
isconnecting=true;
|
||||
BluetoothManager.Instance.Connect(result);
|
||||
// 根据 MAC 在已扫描到的设备列表中查找对应设备
|
||||
// iOS: Address 是 UUID, MacFromBroadcast 是真实 MAC
|
||||
// Android: Address 本身就是 MAC
|
||||
string targetMac = result.ToUpper();
|
||||
var foundDevice = BluetoothManager.Instance.DiscoveredDevices.Find(
|
||||
d => d.GetEffectiveAddress().ToUpper() == targetMac
|
||||
);
|
||||
if (foundDevice != null)
|
||||
{
|
||||
// 找到设备,用正确的地址连接(iOS 用 UUID,Android 用 MAC)
|
||||
BluetoothManager.Instance.Connect(foundDevice.Address);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 未找到,设置 aimMac 让扫描到设备时自动连接
|
||||
BluetoothManager.Instance.ChangeAimMac(result);
|
||||
}
|
||||
LoadingUI.Show();
|
||||
qrCodePlane.SetActive(false);
|
||||
nowDeviceMac=result;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user