diff --git a/product/phone/src/main/ets/model/bluetoothImpl/BluetoothModel.ts b/product/phone/src/main/ets/model/bluetoothImpl/BluetoothModel.ts index db5c2576f380b831079677479dd09a538d474fc7..4dd8643881c223bd509c54b27d5dbf796b78fc4c 100644 --- a/product/phone/src/main/ets/model/bluetoothImpl/BluetoothModel.ts +++ b/product/phone/src/main/ets/model/bluetoothImpl/BluetoothModel.ts @@ -453,23 +453,39 @@ export class BluetoothModel extends BaseModel { }> { LogUtil.info('bluetooth.connectDevice start'); let result = []; - for (let i = 0;i < this.profiles.length; i++) { + + let i = 0; + let func = () => { + if (i > this.profiles.length - 1) { + return; + } + let connectRet = false; if (this.profiles[i]) { let profile = this.profiles[i]; - let connectRet = true; try { profile.connect(deviceId); + connectRet = true; } catch (BusinessError) { LogUtil.info(`${this.TAG} connect failed. BusinessError is ` + JSON.stringify(BusinessError)); - connectRet = false; } result.push({ profileId: i, connectRet: connectRet }); } + + i++; + if (connectRet) { + setTimeout(() => { + func(); + }, 200) + }else{ + func(); + } } - LogUtil.info('bluetooth.connectDevice end, return:' + result); + func(); + + LogUtil.info('bluetooth.connectDevice end, return:' + JSON.stringify(result)); return result; } @@ -567,4 +583,4 @@ export class BluetoothModel extends BaseModel { let bluetoothModel = new BluetoothModel(); -export default bluetoothModel as BluetoothModel; \ No newline at end of file +export default bluetoothModel as BluetoothModel;