This project demonstrates how to create a Bluetooth Low Energy (BLE) peripheral and scanner using React Native.
Before you begin, ensure you have met the following requirements:
- You have installed Node.js and npm.
- You have installed React Native CLI.
- You have a physical device to test (BLE functionality is not supported on simulators).
-
Clone the repository and navigate into the project directory:
git clone https://github.com/your-repo/bluetooth-peripheral-scanner.git cd bluetooth-peripheral-scanner
-
Install the project dependencies:
npm install
-
Install the necessary BLE libraries:
npm install --save react-native-ble-plx react-native-peripheral # or using yarn yarn add react-native-ble-plx react-native-peripheral
-
Enter the
ios
folder and run:cd ios pod update
-
Linking is automatic. Just run
pod install
in theios
directory:pod install
- Manually link the
react-native-ble-plx
andreact-native-peripheral
libraries:react-native link react-native-ble-plx react-native link react-native-peripheral
-
Install CocoaPods if you haven't already:
sudo gem install cocoapods
-
Navigate to the
ios
directory and install the CocoaPods dependencies:cd ios pod install cd ..
-
Ensure your project is correctly set up by running:
npx react-native doctor
-
Validate your Info.plist file:
plutil /Users/qiwen/Desktop/MyBluetoothProject/ios/MyBluetoothProject/Info.plist
-
Open the project workspace in Xcode:
- Open
ios/MyBluetoothProject.xcworkspace
.
- Open
-
Clean the build folder to avoid any derived data issues:
rm -rf ~/Library/Developer/Xcode/DerivedData/*
-
Run the project on your iOS device from Xcode:
- Select your target device and press the run button, or use:
npx react-native run-ios
- Ensure you have the Android development environment set up.
- Run the project using:
npx react-native run-android