z***@hotmail.com
z***@hotmail.com
  • 发布:2025-05-17 23:27
  • 更新:2025-05-17 23:27
  • 阅读:301

微信小程序 ios系统下断开蓝牙卡死问题

分类:uni-app

问题现象

微信小程序部分ios用户,在链接低频蓝牙打印机打印效期贴的时候,存在打印完成内容在断开蓝牙链接的时候整个小程序卡死只能后台杀掉微信进程的情况,安卓目前不存在这种情况,并且很奇怪的是,这个用户有两个微信号,换一个微信号同样的手机和同样的打印机,就没有这个问题

版本

uniapp 版本3.0.0-alpha-3041520220610001
微信 用户使用的都是最新版

问题排查

javascript  
    if (this.connected) {  
      // 埋点  
      try {  
        ArmsFunc.sendException({  
          name: 'before-close-BLE-connection',  
          value: {  
            printStr: str,  
          },  
        });  
      } catch (error) {  
        console.log('error', error);  
      }  
      try {  
        await this.closeBLEConnection(str); // 这里卡死  
      } catch (error) {  
        console.log('closeBLEConnection', error);  
      }  
      // 埋点  
      try {  
        console.log('after-close-BLE-connection');  
        ArmsFunc.sendException({  
          name: 'after-close-BLE-connection',  
          value: {  
            printStr: str,  
          },  
        });  
      } catch (error) {  
        console.log('error', error);  
      }  

  closeBLEConnection(str?: any) {  
    return new Promise((complete) => uni.closeBLEConnection({ complete: (res) => {  
      // 埋点  
      try {  
        ArmsFunc.sendException({  
          name: 'close-BLE-connection-complete',  
          value: {  
            deviceId: this.deviceId,  
            deviceName: this.deviceName,  
            printStr: str,  
          },  
        });  
      } catch (error) {  
        console.log('error', error);  
      }  
      complete(res);  
    }, deviceId: this.deviceId }));  
  }

当前通过埋点排查,每次都是在 'before-close-BLE-connection'点位后边卡主,猜测可能是 uni.closeBLEConnection调用导致整个小程序卡主,目前还不知道原因,盼望大神能够解答,是否是closeBLEConnection前必须调用uni.stopBluetoothDevicesDiscovery()方法?

2025-05-17 23:27 负责人:无 分享
已邀请:

要回复问题请先登录注册