Expo is a platform for rapidly and easily developing React Native apps, and they have added experimental support for Bluetooth! Here's a step-by-step guide to setting up and building a functioning Bluetooth app for iOS.
- Initialize a new Expo project
- Use the "Blank" managed template
- Add dependencies:
expo add react-native-ble-plx @config-plugins/react-native-ble-plx expo-dev-client
- Add
@config-plugins/react-native-ble-plxto apluginsarray in yourapp.json: - (More details on Expo's Bluetooth support here)
- Setup the core code from https://github.com/t3db0t/react-native-bluetooth-example
- Copy and paste the code in
App.js
- Test on physical device (BLE doesn't exist on simulators)
- Plug in phone to computer via USB & unlock
expo run:ios -dorexpo run:android -d- If your device is not listed, you may need to:
- Open XCode
- Go to Window > Devices and Simulators
- Unlock your phone and select your device
- The first time you do
expo runit will prompt you for a bundle identifier. - Expo will attempt to manage signing for you automatically. If it doesn't work, see "Setup XCode and provisioning" below
- Note: using
expo runconverts your project from a "managed" expo workflow to a "bare" workflow.
- Open the app in Expo Go
- The easiest way I've found to connect to the local Metro server is to login to an Expo account on both your computer and your phone. Then your app should appear under "Recently in Development"
- If necessary: Setup XCode and provisioning
- Setup Code Signing: https://expo.fyi/setup-xcode-signing
- Create Provisioning Profile in iOS Developer Portal: https://developer.apple.com/membercenter
- Download and install profile
- Uncheck "Automatically Manage Signing"
- Select downloaded Profile