我正在使用 react-native-bluetooth-serial。每当我尝试通过我的 react native 应用程序连接蓝牙设备时,我都会收到此错误:
错误:读取失败,套接字可能关闭或超时,读取 ret:-1 无法连接到设备
这是我正在尝试做的事情:
connectToDevice () {
if (this.state.discovering) {
return false
} else {
this.setState({ discovering: true })
console.log("searching");
BluetoothSerial.list()
.then((Devices) => {
this.setState({ Devices, discovering: false })
for(var i = 0; 1; i++)
{
if(Devices[i]["name"] == "JBL Flip 3 SE")
{
console.log(Devices[i]["id"]);
BluetoothSerial.connect(Devices[i]["id"]).then((res) => {
console.log(res);
}).catch(err => {
console.log(err);
})
break;
}
}
// console.log(unpairedDevices);
})
.catch((err) => console.log(err.message))
}
}
即使我克隆示例存储库也会发生同样的情况。
知道为什么会这样吗?