反应原生的蓝牙 [英] Bluetooth in react-native
问题描述
我的项目需要接收和发送蓝牙信号,我对 react-native 还很陌生,所以我可以在 react-native 中使用哪个组件来实现蓝牙相关功能?
更新(免责声明):
自从我给出最初的答案后,事情发生了变化.在我的公司 (Polidea),因为我们意识到没有非常好的用于 BT 的 React Native 库,所以我们开发并完全开源(许可许可)我们自己的解决方案.它基于两个基于 RX 的 Android 和 iOS 原生库,我们围绕它编写了一个通用的 React Native 包装器,以便您可以使用相同的 Javascript/RN 接口,但在底层,原生 iOS/Android 细节是在原生代码中处理的.>
图书馆在这里:https://github.com/Polidea/react-native-ble-plx
免责声明:我是首席软件工程师和前首席技术官@Polidea - 创建该库的公司.
原答案:
我认为 RN 中没有用于蓝牙访问的内置组件.
如果您想使用蓝牙,您要么需要编写自己的 Obj-C API 组件(如 https://facebook.github.io/react-native/docs/native-modules-ios.html#content )或使用一些 3rd 方组件适合您的需求,有人已经这样做了.有几个可用的(快速谷歌搜索):
https://github.com/frostney/react-native-bluetooth-state
https://github.com/frostney/react-native-ibeacon
不确定它们是否运行良好,但如果您需要其他功能,可以将它们用作起点.
My project requires to receive&send bluetooth signal, and I am pretty new to react-native so which component I can use in react-native for bluetooth related functionality?
Update (with disclaimer):
Since I gave the original answer, things have changed. In my company (Polidea) since we realised there is no very good library for React Native for BT we developed and fully open-sourced (permissive licence) our own solution. It's based on two RX-based Android and iOS native libraries and we wrote a common React Native wrapper around it so that you can use the same Javascript/RN interface but under the hood native iOS/Android specifics are handled in native code.
The library is here: https://github.com/Polidea/react-native-ble-plx
Disclaimer: I am a Principal Software Engineer and former CTO @Polidea - the company that created the library.
Original answer:
I don't think there is a built-in component for bluetooth access in RN.
If you want to use Bluetooth, you either need to write your own Obj-C API component (as described at https://facebook.github.io/react-native/docs/native-modules-ios.html#content ) or to use some 3rd party components that suit your needs where someone did it already. There are couple of those available (quick google search):
https://github.com/frostney/react-native-bluetooth-state
https://github.com/frostney/react-native-ibeacon
Not sure if they work well, but you can use them as starting point if you need other functionality.
这篇关于反应原生的蓝牙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!