diff --git a/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarBleCentral.swift b/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarBleCentral.swift index f9625ca8..644fda80 100644 --- a/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarBleCentral.swift +++ b/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarBleCentral.swift @@ -23,6 +23,8 @@ final class SmartcarBleCentral: NSObject { private var central: CBCentralManager? private var discovered: [UUID: CBPeripheral] = [:] + /// 扫描时广播里带的本地名(按设备 UUID)。设备名一律优先用它,见 didDiscover 的注释 + private(set) var advertisedNames: [UUID: String] = [:] private(set) var active: SmartcarPeripheral? var onAdapterState: ((String) -> Void)? @@ -161,6 +163,7 @@ final class SmartcarBleCentral: NSObject { return cur } let sp = SmartcarPeripheral(peripheral: p, central: central, delegate: delegate) + sp.advertisedName = advertisedNames[p.identifier] active = sp sp.connect() return sp @@ -196,8 +199,16 @@ extension SmartcarBleCentral: CBCentralManagerDelegate { func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber) { discovered[peripheral.identifier] = peripheral - let name = peripheral.name - ?? (advertisementData[CBAdvertisementDataLocalNameKey] as? String) + // ⚠️ 先取广播本地名,再退回 peripheral.name(2026-09-26)。 + // peripheral.name 是 iOS 缓存的 GAP 名:这台 iPhone 以前连过、那时固件还叫 Smartcar, + // 固件改名 EaiCar 之后缓存不会跟着更新,扫描上报的一直是旧名 → 准入白名单只认 EaiCar, + // 于是「厂商 ID、MAC 都对,iPhone 就是扫不到」,而安卓读的是广播名、一切正常。 + let advName = (advertisementData[CBAdvertisementDataLocalNameKey] as? String)? + .trimmingCharacters(in: .whitespaces) + if let n = advName, !n.isEmpty { advertisedNames[peripheral.identifier] = n } + let name = (advName?.isEmpty == false ? advName : nil) + ?? advertisedNames[peripheral.identifier] + ?? peripheral.name ?? "" let mfg = advertisementData[CBAdvertisementDataManufacturerDataKey] as? Data let svcs = (advertisementData[CBAdvertisementDataServiceUUIDsKey] as? [CBUUID])? diff --git a/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarPeripheral.swift b/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarPeripheral.swift index d401efc1..72863c49 100644 --- a/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarPeripheral.swift +++ b/apps/client/local_plugins/device_smartcar/ios/device_smartcar/Sources/device_smartcar/SmartcarPeripheral.swift @@ -72,7 +72,9 @@ final class SmartcarPeripheral: NSObject { private var jlFound = false var id: String { cb.identifier.uuidString } - var name: String { cb.name ?? "" } + /// 扫描时的广播本地名。有就用它:cb.name 是 iOS 缓存的 GAP 名,固件改过名后会一直是旧名 + var advertisedName: String? + var name: String { (advertisedName?.isEmpty == false ? advertisedName : nil) ?? cb.name ?? "" } var isReady: Bool { state == .ready && cb.state == .connected } init(peripheral: CBPeripheral, central: CBCentralManager, delegate: SmartcarPeripheralDelegate?) {