新版本的IDE(2.6.16)使用用API连接ble蓝牙的时候,uni.onBLEConnectionStateChange,uni.onBLECharacteristicValueChange等回调函数,会随着执行的次数增多持续增加回调次数,比如:第一次执行,则回调一次,断开连接后,再执行就会回调两次,再继续就会回调3次、4次。具体可以看以下日志。
测试的手机系统是安卓9.1.1,手机是荣耀9X
第一次运行
11:10:52.966 App Hide at App.vue:43
11:38:53.360 App Show at App.vue:40
11:38:55.720 A5 at common\lockApi.js:178
11:38:55.740 openBluetooth at common\lockApi.js:178
11:38:55.760 open adapter success: {"errMsg":"openBluetoothAdapter:ok"} at common\lockApi.js:178
11:38:57.780 Device Find:BLE_LOCK,D6:49:C1:11:2C:77 at common\lockApi.js:178
11:38:57.800 connectionDelay:500 at common\lockApi.js:178
11:38:58.280 start connect at common\lockApi.js:178
11:38:58.980 create connection success: {"errMsg":"createBLEConnection:ok"} at common\lockApi.js:178
11:38:59.000 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:00.000 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:00.200 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:00.220 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:00.320 onBLECharacteristicValueChange:d00ea53030a73030ab3439aa3337 at common\lockApi.js:178
11:39:00.340 res:00§00«49ª37 at common\lockApi.js:336
11:39:00.360 success at common\lockApi.js:178
11:39:00.380 close at common\lockApi.js:178
11:39:00.420 close connection success: {"errMsg":"closeBLEConnection:ok"} at common\lockApi.js:178
11:39:00.440 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:00.480 closeBluetoothAdapter success: {"errMsg":"closeBluetoothAdapter:ok"} at common\lockApi.js:178
第二次运行
11:39:08.500 A5 at common\lockApi.js:178
11:39:08.520 openBluetooth at common\lockApi.js:178
11:39:08.540 open adapter success: {"errMsg":"openBluetoothAdapter:ok"} at common\lockApi.js:178
11:39:08.800 Device Find:BLE_LOCK,D6:49:C1:11:2C:77 at common\lockApi.js:178
11:39:08.820 connectionDelay:500 at common\lockApi.js:178
11:39:09.320 start connect at common\lockApi.js:178
11:39:09.961 create connection success: {"errMsg":"createBLEConnection:ok"} at common\lockApi.js:178
11:39:09.981 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:10.001 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:11.001 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:11.021 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:11.221 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:11.241 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:11.261 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:11.381 onBLECharacteristicValueChange:d00ea53030a73030ab3439aa3337 at common\lockApi.js:178
11:39:11.401 res:00§00«49ª37 at common\lockApi.js:336
11:39:11.421 success at common\lockApi.js:178
11:39:11.441 onBLECharacteristicValueChange:d00ea53030a73030ab3439aa3337 at common\lockApi.js:178
11:39:11.461 close at common\lockApi.js:178
11:39:11.481 close connection success: {"errMsg":"closeBLEConnection:ok"} at common\lockApi.js:178
11:39:11.501 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:11.521 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:11.541 closeBluetoothAdapter success: {"errMsg":"closeBluetoothAdapter:ok"} at common\lockApi.js:178
第三次运行
11:39:25.976 A5 at common\lockApi.js:178
11:39:25.996 openBluetooth at common\lockApi.js:178
11:39:26.016 open adapter success: {"errMsg":"openBluetoothAdapter:ok"} at common\lockApi.js:178
11:39:26.316 Device Find:BLE_LOCK,D6:49:C1:11:2C:77 at common\lockApi.js:178
11:39:26.336 connectionDelay:500 at common\lockApi.js:178
11:39:26.836 start connect at common\lockApi.js:178
11:39:27.517 create connection success: {"errMsg":"createBLEConnection:ok"} at common\lockApi.js:178
11:39:27.537 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:27.557 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:27.577 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:28.559 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:28.579 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:28.599 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:28.779 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:28.799 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:28.819 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:28.839 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:28.859 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:28.919 onBLECharacteristicValueChange:d00ea53030a73030ab3439aa3337 at common\lockApi.js:178
11:39:28.939 res:00§00«49ª37 at common\lockApi.js:336
11:39:28.959 success at common\lockApi.js:178
11:39:28.979 onBLECharacteristicValueChange:d00ea53030a73030ab3439aa3337 at common\lockApi.js:178
11:39:28.999 onBLECharacteristicValueChange:d00ea53030a73030ab3439aa3337 at common\lockApi.js:178
11:39:29.019 close at common\lockApi.js:178
11:39:29.039 close connection success: {"errMsg":"closeBLEConnection:ok"} at common\lockApi.js:178
11:39:29.059 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:29.079 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:29.099 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:29.119 closeBluetoothAdapter success: {"errMsg":"closeBluetoothAdapter:ok"} at common\lockApi.js:178
第四次运行
11:39:38.099 A5 at common\lockApi.js:178
11:39:38.119 openBluetooth at common\lockApi.js:178
11:39:38.139 open adapter success: {"errMsg":"openBluetoothAdapter:ok"} at common\lockApi.js:178
11:39:38.859 Device Find:BLE_LOCK,D6:49:C1:11:2C:77 at common\lockApi.js:178
11:39:38.879 connectionDelay:500 at common\lockApi.js:178
11:39:39.379 start connect at common\lockApi.js:178
11:39:39.999 create connection success: {"errMsg":"createBLEConnection:ok"} at common\lockApi.js:178
11:39:40.019 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:40.039 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:40.059 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:40.079 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:41.019 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:41.039 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:41.059 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:41.079 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:41.239 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:41.259 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:41.279 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:41.299 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:41.319 write characteristics failed: {"errMsg":"writeBLECharacteristicValue:fail property not support","errCode":10007} at common\lockApi.js:178
11:39:41.339 reConnection at common\lockApi.js:178
11:39:41.359 close connection success: {"errMsg":"closeBLEConnection:ok"} at common\lockApi.js:178
11:39:41.379 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:41.399 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:41.419 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:41.439 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:41.479 connectionDelay:500 at common\lockApi.js:178
11:39:41.499 connectionDelay:500 at common\lockApi.js:178
11:39:41.519 connectionDelay:500 at common\lockApi.js:178
11:39:41.539 connectionDelay:500 at common\lockApi.js:178
11:39:41.999 start connect at common\lockApi.js:178
11:39:42.039 create connection success: {"errMsg":"createBLEConnection:ok"} at common\lockApi.js:178
11:39:42.059 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:42.079 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:42.099 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:42.119 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":true} at common\lockApi.js:178
11:39:43.079 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:43.099 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:43.119 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:43.139 set notify success: {"errMsg":"notifyBLECharacteristicValueChange:ok"} at common\lockApi.js:178
11:39:43.299 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:43.319 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:43.339 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:43.359 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:43.379 write characteristics success: {"errMsg":"writeBLECharacteristicValue:ok"} at common\lockApi.js:178
11:39:43.419 onBLECharacteristicValueChange:d005a53030 at common\lockApi.js:178
11:39:43.439 res:00 at common\lockApi.js:336
11:39:43.459 success at common\lockApi.js:178
11:39:43.479 onBLECharacteristicValueChange:d005a53030 at common\lockApi.js:178
11:39:43.499 onBLECharacteristicValueChange:d005a53030 at common\lockApi.js:178
11:39:43.519 onBLECharacteristicValueChange:d005a53030 at common\lockApi.js:178
11:39:43.539 close at common\lockApi.js:178
11:39:43.559 close connection success: {"errMsg":"closeBLEConnection:ok"} at common\lockApi.js:178
11:39:43.579 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:43.599 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:43.619 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:43.639 onBLEConnectionStateChange: {"deviceId":"D6:49:C1:11:2C:77","connected":false} at common\lockApi.js:178
11:39:43.659 closeBluetoothAdapter success: {"errMsg":"closeBluetoothAdapter:ok"} at common\lockApi.js:178
1***@qq.com
试了一下,暂时没发现断开连接问题
2020-10-08 11:11
1***@qq.com
writeBLECharacteristicValue:fail property not support 华为荣耀打印时好时坏就出现这个原因,其他手机没问题
2020-11-09 16:13
两个纠缠之缘
回复 1***@qq.com: 老哥一样啊 有时候会出现这个问题 有什么解决办法吗
2021-09-24 14:49
7***@qq.com
HBuilderX 3.6.4版本 没解决鸭
2022-11-10 11:28