What is the workflow for developing apps that use Bluetooth?

I’m developing an iOS app that requires BLE but am confused as to the current state and workflow for getting Bluetooth into my app using Expo’s tools.

So far I gather there are some constraints that I must work around:

  • Simulator does not support Bluetooth
  • Expo Go does not support Bluetooth

So (and I’m new to this so be patient) I gather that means I must either

  • expo run:ios -d and run on a connected device, or
  • eas build -p ios and download to devices.

But what’s unclear (and I may not even have the above quite right, in fact I’d be happy to know that it’s not that complex) is how to access Bluetooth in the first place. I see that the Expo API provides access to all kinds of platform functionality, but don’t see Bluetooth anywhere there. I gather that in order to use Bluetooth, I must use react-native-ble-plx (ignoring the part where it says my project needs to be “ejected”?) for which I need to add a corresponding plugin with

yarn add @config-plugins/react-native-ble-plx expo-dev-client

and and the corresponding entry under expo.plugins in my app.json.

Do I have that right? Will those steps then give me access to platform Bluetooth (though not in Expo Go or Simulator)?

I’d try this all myself, but it’s unclear to me what instructions are current and which ones are old, and in any case in order to do this (specifically expo run:ios -d or eas build -p ios) I will need to start paying for an Apple Developer account sooner than I had intended and buy a new Mac.

Finally, I wonder whether (and like to hope that) using the corresponding (react-native-blemulator) might obviate the need for all of this by making it unnecessary to actually use Bluetooth at all (doing initial development) so that I could continue to use Expo Go and Simulator?

Hi @orome

Yes, you’ve got it right. EAS Build and config plugins are still relatively new and many packages have not updated their instructions to account for it. Even for ones that have, it can be unclear exactly which parts of the instructions apply to a plain React Native app vs. an Expo app with EAS Build (and it gets worse when they include instructions for versions of React Native < 0.60 and manual linking etc.)

In the case of react-native-ble-plx, the Expo Team has written a config plugin. So the react-native-ble-plx project themselves does not support Expo managed workflow apps, but with the config plugin it should work perfectly. (I haven’t tried react-native-ble-plx myself, but during the build process the config plugin makes the necessary changes to the native code that are mentioned in the react-native-ble-plx installation instructions.)

Not exactly.

You can run eas build -p ios with different profiles depending on whether you want to build a development client, “ad-hoc” or production build.

These are the profiles that are created by default in eas.json:

  • --profile development will build a dev client, assuming you installed expo-dev-client. This is basically a custom version of Expo Go that includes all of the dependencies from your package.json (and only those dependencies. So e.g. it will be missing expo-filesystem unless you explicitly installed that, whereas Expo Go includes the native code for the whole Expo SDK.)
  • --profile internal will build an app with an ad-hoc or enterprise provisioning profile. See Internal distribution - Expo Documentation
  • --profile production will of course build a production app for submission to the App Store.

You can of course also build for the simulator: Building for iOS simulators - Expo Documentation

So you can build a replacement for Expo Go using the development profile and use that for development. It is not necessary to use expo run for a normal managed app and I avoid it because of the side effects. It might be helpful if you’re debugging build problems and of course if you’re writing your own native code as part of the app.

If you use Expo’s build servers (i.e. you avoid expo run and eas build --local) and as long as you have a physical device to test on then you do not need a Mac at all. Of course if you need to run the app on a Simulator then you will need a Mac.

Cool! I didn’t know about that project. Unfortunately it includes some native code, so it will also not work in Expo Go (But! See below). Generally if a package has android and ios directories or mentions linking or pod install etc. then, unless it is part of the Expo SDK, it will not work in Expo Go.

OK, so when they say it won’t work in Expo Go what they really mean is that the custom native code does not exist in Expo Go, so if you try to call it you will get errors. But you can technically still run an app that uses something like react-native-ble-plx as long as you avoid calling that code in development mode. If the whole point of your app is to do something with Bluetooth this is not likely to be useful, of course.

So if you can omit the features of the app that need react-native-ble-plx or mock them somehow then you should still be able to develop in Expo Go.

e.g.:

if (__DEV__) {
  thisShouldNotCallRealBluetoothCode();
} else {
  // call the real react-native-ble-plx code
}
1 Like

It turns out that react-native-blemulator doesn’t really work, but your post solved all my other BLE problems, so I’m on the road to getting my BLE environment set up (I just need to build an emulator for my device now).

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.