From ed9904ef3f9f5d2a65c5101d9810147fa3bef3b8 Mon Sep 17 00:00:00 2001 From: dos1in Date: Fri, 6 Mar 2026 19:53:09 +0800 Subject: [PATCH 01/11] Update index.ios.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 统一处理日志信息,防止吞掉内部错误 --- .../platform/api/ble-connection/index.ios.js | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index d5233f8253..fb76950421 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -56,7 +56,12 @@ const removeUpdateStateSubscription = function () { updateStateSubscription = null } } -const commonFailHandler = function (errMsg, fail, complete) { +const commonFailHandler = function (errMsg, fail, complete, reason) { + if (reason instanceof Error) { + errMsg = errMsg + ' ' + reason.message + } else if (reason !== undefined && reason !== null) { + errMsg = errMsg + ' ' + reason + } const result = { errMsg } @@ -80,12 +85,12 @@ function openBluetoothAdapter (options = {}) { // 先请求权限,再初始化蓝牙管理器 bluetoothPermission().then((hasPermissions) => { if (!hasPermissions) { - commonFailHandler('openBluetoothAdapter:fail no permission', fail, complete) + commonFailHandler('openBluetoothAdapter:fail', fail, complete, 'no permission') return } if (bleManagerInitialized) { - commonFailHandler('openBluetoothAdapter:fail already opened', fail, complete) + commonFailHandler('openBluetoothAdapter:fail', fail, complete, 'already opened') return } @@ -103,17 +108,17 @@ function openBluetoothAdapter (options = {}) { success(result) complete(result) } else { - commonFailHandler('openBluetoothAdapter:fail bluetooth not enabled', fail, complete) + commonFailHandler('openBluetoothAdapter:fail', fail, complete, 'bluetooth not enabled') } }).catch((error) => { - commonFailHandler('openBluetoothAdapter:fail ' + (typeof error === 'string' ? error : ''), fail, complete) + commonFailHandler('openBluetoothAdapter:fail', fail, complete, error) }) }, 1000) }).catch((error) => { - commonFailHandler('openBluetoothAdapter:fail ' + (typeof error === 'string' ? error : ''), fail, complete) + commonFailHandler('openBluetoothAdapter:fail', fail, complete, error) }) - }).catch(() => { - commonFailHandler('openBluetoothAdapter:fail no permission', fail, complete) + }).catch((error) => { + commonFailHandler('openBluetoothAdapter:fail', fail, complete, error) }) } @@ -194,7 +199,7 @@ function startBluetoothDevicesDiscovery (options = {}) { } = options if (!bleManagerInitialized) { - commonFailHandler('startBluetoothDevicesDiscovery:fail ble adapter hans\'t been opened or ble is unavailable.', fail, complete) + commonFailHandler('startBluetoothDevicesDiscovery:fail', fail, complete, 'ble adapter hans\'t been opened or ble is unavailable.') return } DiscoverPeripheralSubscription = BleManager.onDiscoverPeripheral((device) => { @@ -247,7 +252,7 @@ function startBluetoothDevicesDiscovery (options = {}) { success(result) complete(result) }).catch((error) => { - commonFailHandler('startBluetoothDevicesDiscovery:fail ' + (typeof error === 'string' ? error : ''), fail, complete) + commonFailHandler('startBluetoothDevicesDiscovery:fail', fail, complete, error) }) } @@ -256,7 +261,7 @@ function stopBluetoothDevicesDiscovery (options = {}) { const { success = noop, fail = noop, complete = noop } = options if (!bleManagerInitialized) { - commonFailHandler('stopBluetoothDevicesDiscovery:fail ble adapter hans\'t been opened or ble is unavailable.', fail, complete) + commonFailHandler('stopBluetoothDevicesDiscovery:fail', fail, complete, 'ble adapter hans\'t been opened or ble is unavailable.') return } removeBluetoothDevicesDiscovery() @@ -276,7 +281,7 @@ function stopBluetoothDevicesDiscovery (options = {}) { success(result) complete(result) }).catch((error) => { - commonFailHandler('stopBluetoothDevicesDiscovery:fail ' + (typeof error === 'string' ? error : ''), fail, complete) + commonFailHandler('stopBluetoothDevicesDiscovery:fail', fail, complete, error) }) } @@ -298,7 +303,7 @@ function getConnectedBluetoothDevices (options = {}) { const { services = [], success = noop, fail = noop, complete = noop } = options if (!bleManagerInitialized) { - commonFailHandler('getConnectedBluetoothDevices:fail 请先调用 wx.openBluetoothAdapter 接口进行初始化操作', fail, complete) + commonFailHandler('getConnectedBluetoothDevices:fail', fail, complete, '请先调用 wx.openBluetoothAdapter 接口进行初始化操作') return } @@ -314,7 +319,7 @@ function getConnectedBluetoothDevices (options = {}) { success(result) complete(result) }).catch((error) => { - commonFailHandler('getConnectedBluetoothDevices:fail ' + (typeof error === 'string' ? error : ''), fail, complete) + commonFailHandler('getConnectedBluetoothDevices:fail', fail, complete, error) }) } @@ -323,7 +328,7 @@ function getBluetoothAdapterState (options = {}) { const { success = noop, fail = noop, complete = noop } = options if (!bleManagerInitialized) { - commonFailHandler('getBluetoothAdapterState:fail ble adapter need open first.', fail, complete) + commonFailHandler('getBluetoothAdapterState:fail', fail, complete, 'ble adapter need open first.') return } @@ -336,7 +341,7 @@ function getBluetoothAdapterState (options = {}) { success(result) complete(result) }).catch((error) => { - commonFailHandler('getBluetoothAdapterState:fail ' + (typeof error === 'string' ? error : ''), fail, complete) + commonFailHandler('getBluetoothAdapterState:fail', fail, complete, error) }) } function onDidUpdateState () { @@ -573,15 +578,15 @@ function setBLEMTU (options = {}) { const BleManager = require('react-native-ble-manager').default const { deviceId, mtu, success = noop, fail = noop, complete = noop } = options if (!mtu) { - commonFailHandler('setBLEMTU:fail parameter error: parameter.mtu should be Number instead of Undefined;', fail, complete) + commonFailHandler('setBLEMTU:fail', fail, complete, 'parameter error: parameter.mtu should be Number instead of Undefined;') return } if (!deviceId) { - commonFailHandler('setBLEMTU:fail parameter error: parameter.deviceId should be String instead of Undefined;', fail, complete) + commonFailHandler('setBLEMTU:fail', fail, complete, 'parameter error: parameter.deviceId should be String instead of Undefined;') return } if (!deviceId && !mtu) { - commonFailHandler('setBLEMTU:fail parameter error: parameter.deviceId should be String instead of Undefined;parameter.mtu should be Number instead of Undefined;', fail, complete) + commonFailHandler('setBLEMTU:fail', fail, complete, 'parameter error: parameter.deviceId should be String instead of Undefined;parameter.mtu should be Number instead of Undefined;') return } From 812c7cc7d950a5b24914df1cee3d60420fa4805d Mon Sep 17 00:00:00 2001 From: dos1in Date: Fri, 6 Mar 2026 19:54:25 +0800 Subject: [PATCH 02/11] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20!deviceId=20&?= =?UTF-8?q?&=20!mtu=20=E6=B0=B8=E8=BF=9C=E4=B8=BA=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/platform/api/ble-connection/index.ios.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index fb76950421..342bbf9bc0 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -577,6 +577,10 @@ function offBLECharacteristicValueChange (callback) { function setBLEMTU (options = {}) { const BleManager = require('react-native-ble-manager').default const { deviceId, mtu, success = noop, fail = noop, complete = noop } = options + if (!deviceId && !mtu) { + commonFailHandler('setBLEMTU:fail', fail, complete, 'parameter error: parameter.deviceId should be String instead of Undefined;parameter.mtu should be Number instead of Undefined;') + return + } if (!mtu) { commonFailHandler('setBLEMTU:fail', fail, complete, 'parameter error: parameter.mtu should be Number instead of Undefined;') return @@ -585,10 +589,6 @@ function setBLEMTU (options = {}) { commonFailHandler('setBLEMTU:fail', fail, complete, 'parameter error: parameter.deviceId should be String instead of Undefined;') return } - if (!deviceId && !mtu) { - commonFailHandler('setBLEMTU:fail', fail, complete, 'parameter error: parameter.deviceId should be String instead of Undefined;parameter.mtu should be Number instead of Undefined;') - return - } BleManager.requestMTU(deviceId, mtu).then((actualMtu) => { const result = { From b7b6f68257761147e8aa5b1aa006545981cf0e50 Mon Sep 17 00:00:00 2001 From: dos1in Date: Tue, 10 Mar 2026 14:10:52 +0800 Subject: [PATCH 03/11] =?UTF-8?q?fix:=20offBluetoothAdapterStateChange=20?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E7=A7=BB=E9=99=A4=E6=89=80=E6=9C=89=E7=9A=84?= =?UTF-8?q?=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/platform/api/ble-connection/index.ios.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index 342bbf9bc0..cac83fb8cb 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -379,14 +379,9 @@ function onBluetoothAdapterStateChange (callback) { } } -function offBluetoothAdapterStateChange (callback) { - const index = onStateChangeCallbacks.indexOf(callback) - if (index > -1) { - onStateChangeCallbacks.splice(index, 1) - } - if (deviceFoundCallbacks.length === 0) { - removeUpdateStateSubscription() - } +function offBluetoothAdapterStateChange () { + onStateChangeCallbacks.length = 0 + removeUpdateStateSubscription() } function getBluetoothDevices (options = {}) { // 该能力只是获取应用级别已连接设备列表,非手机级别的已连接设备列表 From d7ffca5f33da12caea5f84afcc0aa3f376288829 Mon Sep 17 00:00:00 2001 From: dos1in Date: Tue, 10 Mar 2026 14:12:28 +0800 Subject: [PATCH 04/11] =?UTF-8?q?fix:=20=E4=B8=8D=E4=BC=A0=E6=AD=A4?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=88=99=E7=A7=BB=E9=99=A4=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/platform/api/ble-connection/index.ios.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index cac83fb8cb..4f5b2f199c 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -824,9 +824,13 @@ function onBLEConnectionStateChange (callback) { } function offBLEConnectionStateChange (callback) { - const index = onBLEConnectionStateCallbacks.indexOf(callback) - if (index !== -1) { - onBLEConnectionStateCallbacks.splice(index, 1) + if (callback == null) { + onBLEConnectionStateCallbacks.length = 0 + } else { + const index = onBLEConnectionStateCallbacks.indexOf(callback) + if (index !== -1) { + onBLEConnectionStateCallbacks.splice(index, 1) + } } if (onBLEConnectionStateCallbacks.length === 0) { removeUpdateStateSubscription() From 01d8e3e8fa7ee95e450f50716b363c688bf1e46c Mon Sep 17 00:00:00 2001 From: dos1in Date: Tue, 10 Mar 2026 14:14:02 +0800 Subject: [PATCH 05/11] =?UTF-8?q?fix:=20=E9=B8=BF=E8=92=99=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E8=B0=83=E7=94=A8=20write=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-proxy/src/platform/api/ble-connection/index.ios.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index 4f5b2f199c..adb2db75cf 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -416,8 +416,8 @@ function writeBLECharacteristicValue (options = {}) { } let writeTypeValue = writeType if (!writeType) { - // 与小程序拉齐 iOS 未传值的情况优先 write,安卓优先 writeNoResponse 。 - writeTypeValue = __mpx_mode__ === 'ios' ? 'write' : 'writeNoResponse' + // 与小程序拉齐:iOS / 鸿蒙未传值优先 write,安卓优先 writeNoResponse 。 + writeTypeValue = (__mpx_mode__ === 'ios' || __mpx_mode__ === 'harmony') ? 'write' : 'writeNoResponse' } // 将ArrayBuffer转换为byte array const bytes = Array.from(new Uint8Array(value)) From 8c2d331004f9e6d4b5e5644acb01a8c251626009 Mon Sep 17 00:00:00 2001 From: dos1in Date: Tue, 10 Mar 2026 14:19:25 +0800 Subject: [PATCH 06/11] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-proxy/src/platform/api/ble-connection/index.ios.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index adb2db75cf..029793a26b 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -57,10 +57,8 @@ const removeUpdateStateSubscription = function () { } } const commonFailHandler = function (errMsg, fail, complete, reason) { - if (reason instanceof Error) { - errMsg = errMsg + ' ' + reason.message - } else if (reason !== undefined && reason !== null) { - errMsg = errMsg + ' ' + reason + if (reason != null) { + errMsg = errMsg + ' ' + (reason.message != null ? reason.message : String(reason)) } const result = { errMsg From c216df7d95c216c58eade3c99ee80343ca23ea44 Mon Sep 17 00:00:00 2001 From: dos1in Date: Fri, 13 Mar 2026 10:58:26 +0800 Subject: [PATCH 07/11] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=20offBluetoothA?= =?UTF-8?q?dapterStateChange=20=E6=94=AF=E6=8C=81=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=20callback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/platform/api/ble-connection/index.ios.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index 029793a26b..6cdd85ce3c 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -377,9 +377,19 @@ function onBluetoothAdapterStateChange (callback) { } } -function offBluetoothAdapterStateChange () { - onStateChangeCallbacks.length = 0 - removeUpdateStateSubscription() +// 注意:微信官方文档标识没有标识 API 不支持传入 callback 参数,但实际测试发现支持传入 callback 进行移除指定回调 +function offBluetoothAdapterStateChange (callback) { + if (callback == null) { + onStateChangeCallbacks.length = 0 + } else { + const index = onStateChangeCallbacks.indexOf(callback) + if (index !== -1) { + onStateChangeCallbacks.splice(index, 1) + } + } + if (onStateChangeCallbacks.length === 0) { + removeUpdateStateSubscription() + } } function getBluetoothDevices (options = {}) { // 该能力只是获取应用级别已连接设备列表,非手机级别的已连接设备列表 From 2bd5479056a9dd9ff55d9f5eb2823959e3df4f49 Mon Sep 17 00:00:00 2001 From: dos1in Date: Fri, 13 Mar 2026 11:15:53 +0800 Subject: [PATCH 08/11] =?UTF-8?q?fix:=20bluetoothDeviceFound=20=E5=8F=AA?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=9B=9E?= =?UTF-8?q?=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/api/ble-connection/index.ios.js | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index 6cdd85ce3c..3f87b74e96 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -10,7 +10,7 @@ let DiscoverPeripheralSubscription = null let updateStateSubscription = null let discovering = false let getDevices = [] // 记录已扫描的设备列表 -const deviceFoundCallbacks = [] +let deviceFoundCallback = null // 仅允许一个回调,重复添加会被覆盖 const onStateChangeCallbacks = [] const characteristicCallbacks = [] const onBLEConnectionStateCallbacks = [] @@ -153,7 +153,7 @@ function closeBluetoothAdapter (options = {}) { BleManager.disconnect(id).catch(() => {}) }) connectedDevices.clear() - deviceFoundCallbacks.length = 0 + deviceFoundCallback = null onStateChangeCallbacks.length = 0 characteristicCallbacks.length = 0 onBLEConnectionStateCallbacks.length = 0 @@ -222,13 +222,11 @@ function startBluetoothDevicesDiscovery (options = {}) { return } } - deviceFoundCallbacks.forEach(cb => { - if (type(cb) === 'Function') { - cb({ - devices: [deviceInfo] - }) - } - }) + if (type(deviceFoundCallback) === 'Function') { + deviceFoundCallback({ + devices: [deviceInfo] + }) + } getDevices.push(deviceInfo) // 处理设备发现逻辑 }) @@ -284,16 +282,11 @@ function stopBluetoothDevicesDiscovery (options = {}) { } function onBluetoothDeviceFound (callback) { - if (deviceFoundCallbacks.indexOf(callback) === -1) { - deviceFoundCallbacks.push(callback) - } + deviceFoundCallback = callback // 只允许一个回调,重复添加被最新覆盖 } -function offBluetoothDeviceFound (callback) { - const index = deviceFoundCallbacks.indexOf(callback) - if (index > -1) { - deviceFoundCallbacks.splice(index, 1) - } +function offBluetoothDeviceFound () { + deviceFoundCallback = null // 移除所有回调(当前仅有一个) } function getConnectedBluetoothDevices (options = {}) { From bfedfe41a4bb9009e5261d05a1aa69f084b6512a Mon Sep 17 00:00:00 2001 From: dos1in Date: Fri, 13 Mar 2026 13:25:37 +0800 Subject: [PATCH 09/11] =?UTF-8?q?fix:=20=E4=BB=85=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=20BLE=20=E7=89=B9=E5=BE=81=E5=80=BC=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E5=9B=9E=E8=B0=83=EF=BC=8C=E4=BC=98=E5=8C=96=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/api/ble-connection/index.ios.js | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index 3f87b74e96..6000e8446f 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -11,8 +11,8 @@ let updateStateSubscription = null let discovering = false let getDevices = [] // 记录已扫描的设备列表 let deviceFoundCallback = null // 仅允许一个回调,重复添加会被覆盖 +let characteristicCallback = null // 仅允许一个回调,重复添加会被覆盖 const onStateChangeCallbacks = [] -const characteristicCallbacks = [] const onBLEConnectionStateCallbacks = [] let characteristicSubscriptions = {} const connectedDevices = new Set() @@ -155,7 +155,7 @@ function closeBluetoothAdapter (options = {}) { connectedDevices.clear() deviceFoundCallback = null onStateChangeCallbacks.length = 0 - characteristicCallbacks.length = 0 + characteristicCallback = null onBLEConnectionStateCallbacks.length = 0 if (valueForCharacteristicSubscriptions) { valueForCharacteristicSubscriptions.remove() @@ -532,10 +532,11 @@ function notifyBLECharacteristicValueChange (options = {}) { let valueForCharacteristicSubscriptions = null function onBLECharacteristicValueChange (callback) { + characteristicCallback = callback // 只允许一个回调,重复添加被最新覆盖 const BleManager = require('react-native-ble-manager').default - if (characteristicCallbacks.length === 0) { + if (!valueForCharacteristicSubscriptions) { valueForCharacteristicSubscriptions = BleManager.onDidUpdateValueForCharacteristic((data) => { - // 将byte array转换为ArrayBuffer + if (type(characteristicCallback) !== 'Function') return const buffer = new ArrayBuffer(data.value.length) const view = new Uint8Array(buffer) data.value.forEach((byte, index) => { @@ -547,24 +548,14 @@ function onBLECharacteristicValueChange (callback) { characteristicId: data.characteristic, value: buffer } - characteristicCallbacks.forEach(cb => { - if (type(cb) === 'Function') { - cb(result) - } - }) + characteristicCallback(result) }) } - if (characteristicCallbacks.indexOf(callback) === -1) { - characteristicCallbacks.push(callback) - } } -function offBLECharacteristicValueChange (callback) { - const index = characteristicCallbacks.indexOf(callback) - if (index > -1) { - characteristicCallbacks.splice(index, 1) - } - if (characteristicCallbacks.length === 0 && valueForCharacteristicSubscriptions) { +function offBLECharacteristicValueChange () { + characteristicCallback = null + if (valueForCharacteristicSubscriptions) { valueForCharacteristicSubscriptions.remove() valueForCharacteristicSubscriptions = null } From fae00a584b3c73eb7ffae5bac320b19f56e7ab85 Mon Sep 17 00:00:00 2001 From: dos1in Date: Fri, 13 Mar 2026 15:19:00 +0800 Subject: [PATCH 10/11] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E5=8F=AA=E6=8E=A5=E5=8F=97=E5=87=BD=E6=95=B0=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api-proxy/src/platform/api/ble-connection/index.ios.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index 6000e8446f..e82d08f7e4 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -282,6 +282,7 @@ function stopBluetoothDevicesDiscovery (options = {}) { } function onBluetoothDeviceFound (callback) { + if (type(callback) !== 'Function') return deviceFoundCallback = callback // 只允许一个回调,重复添加被最新覆盖 } @@ -362,6 +363,7 @@ function onDidUpdateState () { } function onBluetoothAdapterStateChange (callback) { + if (type(callback) !== 'Function') return if (!updateStateSubscription) { onDidUpdateState() } @@ -532,6 +534,7 @@ function notifyBLECharacteristicValueChange (options = {}) { let valueForCharacteristicSubscriptions = null function onBLECharacteristicValueChange (callback) { + if (type(callback) !== 'Function') return characteristicCallback = callback // 只允许一个回调,重复添加被最新覆盖 const BleManager = require('react-native-ble-manager').default if (!valueForCharacteristicSubscriptions) { @@ -807,6 +810,7 @@ function closeBLEConnection (options = {}) { } function onBLEConnectionStateChange (callback) { + if (type(callback) !== 'Function') return if (!updateStateSubscription) { onDidUpdateState() } From 118b48c22db98adb5f8042d12233e5fd99416281 Mon Sep 17 00:00:00 2001 From: dos1in Date: Fri, 13 Mar 2026 15:21:34 +0800 Subject: [PATCH 11/11] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5=E5=B9=B6=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E8=AD=A6=E5=91=8A=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E5=8F=AA=E6=8E=A5=E5=8F=97=E5=87=BD=E6=95=B0=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/api/ble-connection/index.ios.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js index e82d08f7e4..c9b8c84807 100644 --- a/packages/api-proxy/src/platform/api/ble-connection/index.ios.js +++ b/packages/api-proxy/src/platform/api/ble-connection/index.ios.js @@ -282,7 +282,10 @@ function stopBluetoothDevicesDiscovery (options = {}) { } function onBluetoothDeviceFound (callback) { - if (type(callback) !== 'Function') return + if (type(callback) !== 'Function') { + console.warn('onBluetoothDeviceFound: callback 应为函数,已忽略') + return + } deviceFoundCallback = callback // 只允许一个回调,重复添加被最新覆盖 } @@ -363,7 +366,10 @@ function onDidUpdateState () { } function onBluetoothAdapterStateChange (callback) { - if (type(callback) !== 'Function') return + if (type(callback) !== 'Function') { + console.warn('onBluetoothAdapterStateChange: callback 应为函数,已忽略') + return + } if (!updateStateSubscription) { onDidUpdateState() } @@ -534,7 +540,10 @@ function notifyBLECharacteristicValueChange (options = {}) { let valueForCharacteristicSubscriptions = null function onBLECharacteristicValueChange (callback) { - if (type(callback) !== 'Function') return + if (type(callback) !== 'Function') { + console.warn('onBLECharacteristicValueChange: callback 应为函数,已忽略') + return + } characteristicCallback = callback // 只允许一个回调,重复添加被最新覆盖 const BleManager = require('react-native-ble-manager').default if (!valueForCharacteristicSubscriptions) { @@ -810,7 +819,10 @@ function closeBLEConnection (options = {}) { } function onBLEConnectionStateChange (callback) { - if (type(callback) !== 'Function') return + if (type(callback) !== 'Function') { + console.warn('onBLEConnectionStateChange: callback 应为函数,已忽略') + return + } if (!updateStateSubscription) { onDidUpdateState() }