英文:
Can't connect to a device using react-native-bluetooth-classic
问题
我正在尝试使用"react-native-bluetooth-classic"将数据从一部安卓手机发送到另一部。我成功地运行了存储库中的示例,但我无法连接到配对的设备。有时,我可以连接到一部手机,但另一部手机无法连接回来。
是否需要对手机的蓝牙进行任何配置?
英文:
I am trying to send data from one android phone to another using "react-native-bluetooth-classic". I successfully run the example in the repo, but I am not able to connect to the paired devices. Sometimes, I can connect to a phone but the other can't connect back.
Is there any configuration I should to the phone's bluetooth?
答案1
得分: 2
已合并昨晚的拉取请求,现在应该可以使用提供的 BluetoothClassicExample
应用程序中设备列表底部的 接受连接
按钮,从一个设备连接到另一个设备。
async acceptConnections() {
console.log("应用正在接受连接...");
this.setState({ isAccepting: true });
try {
let connectedDevice = await RNBluetoothClassic.accept();
if (connectedDevice) { // 如果取消了连接,则为未定义
this.setState({ connectedDevice, isAccepting: false });
}
} catch(error) {
console.log(error);
this.refs.toast.show(
`无法接受客户端连接`,
DURATION.LENGTH_SHORT
);
this.setState({ isAccepting: false });
}
}
这仅适用于 Android,因为据我所知,在 iOS 上没有办法查看连接情况。我成功将我的 Android 设备连接到我的 iOS 设备使用示例应用程序,但由于缺少 Android MFi 协议,数据只是被发送到 iOS 中而不会被处理。
英文:
Merged the pull request last night, should be able to connect from one device to another with the provided BluetoothClassicExample
app using the Accept Connection
button at the bottom of the device list.
async acceptConnections() {
console.log("App is accepting connections now...");
this.setState({ isAccepting: true });
try {
let connectedDevice = await RNBluetoothClassic.accept();
if (connectedDevice) { // Undefined if cancelled
this.setState({ connectedDevice, isAccepting: false });
}
} catch(error) {
console.log(error);
this.refs.toast.show(
`Unable to accept client connection`,
DURATION.LENGTH_SHORT
);
this.setSTate({ isAccepting: false });
}
}
This is only available on Android as from what I've seen, there are no ways to see the connection on IOS. I was able to connect my Android to my IOS using the example app, but without the Android MFi protocols, the data just gets sent into the IOS void.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论