React Native Bluetooth Serial

screenshot of React Native Bluetooth Serial
react-native

React Native Bluetooth Serial

Port of https://github.com/don/BluetoothSerial for react native

Overview:

React Native Bluetooth Serial is a library that provides a React Native version of the BluetoothSerial plugin, supporting both Android and iOS platforms. The library is compatible with React Native versions >= 0.25, with no guarantees for older versions.

Features:

  • Cross-Platform Support: Compatible with both Android and iOS devices.
  • Bluetooth Connectivity: Enable and disable Bluetooth, list available devices, and discover unpaired devices.
  • Reading and Writing: Functions for reading and writing data from connected peripheral devices.
  • API Methods: Various methods tested on both Android and iOS devices, returning promises for asynchronous operations.

Installation:

For iOS:

  1. Install the package via npm:
    npm i -S react-native-bluetooth-serial
    
  2. In Xcode, right click on Libraries -> Add Files to [your project's name], then add RCTBluetoothSerial.xcodeproj.
  3. Select your project in Xcode, go to Build Phases -> Link Binary With Libraries, and add libRCTBluetoothSerial.a.
  4. Ensure 'All' is toggled on in the Build Settings, add $(SRCROOT)/../../react-native/React and $(SRCROOT)/../../../React to Header Search Paths.
  5. Run your project (Cmd+R) in Xcode.

For Android:

  1. Install the package via npm:
    npm i -S react-native-bluetooth-serial
    
  2. Open MainActivity.java or MainApplication.java and add import com.rusel.RCTBluetoothSerial.*; to the imports.
  3. Add new RCTBluetoothSerialPackage() to the list returned by the getPackages() method.
  4. Update android/settings.gradle and android/app/build.gradle with the provided code snippets.

Summary:

React Native Bluetooth Serial is a useful library for integrating Bluetooth functionality into React Native apps. It offers cross-platform support, Bluetooth connectivity features, and API methods for interacting with Bluetooth devices. The installation process involves linking the library with Xcode for iOS and making modifications to Android project files for Android compatibility.

react-native
React Native

React Native is a framework for building mobile applications using React and JavaScript. It enables developers to write once and deploy to multiple platforms, including iOS, Android, and the web, while providing a native app-like experience to users.