原生蓝牙 [英] Bluetooth in react-native

查看:121
本文介绍了原生蓝牙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目需要接收并发送蓝牙信号,而我对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://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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆