react-native-ble-advertiser icon indicating copy to clipboard operation
react-native-ble-advertiser copied to clipboard

Does it work with Expo?

Open leodevbro opened this issue 1 year ago • 13 comments

I mean, should I start a new RN project using Expo or using RN CLI? As far as I know, Expo has some limitations of accessing device modules like Camera, Bluetooth.

leodevbro avatar Jul 02 '23 17:07 leodevbro

I guess first the config plugin should be created for that... https://docs.expo.dev/config-plugins/plugins-and-mods/

Because the same case exists react-native-ble-plx library. In order to use the library on expo, we need to add a config plugin in app.json file like this:

Ekran Resmi 2023-09-03 15 23 23

yusufipsum avatar Sep 03 '23 12:09 yusufipsum

Hey, did you figure how to make it run on expo? @leodevbro Thanks

did you figure how to make it run on expo?

Here is another conversation about it: https://github.com/vitorpamplona/react-native-ble-advertiser/issues/21

Unfortunately it seems we have no progress on it.

leodevbro avatar Nov 03 '23 14:11 leodevbro

@JoseOliveira-sensefinity @leodevbro It works for me but with an additional EAS setup and build https://docs.expo.dev/build/setup/

In my project, I've already had EAS setup so It worked, but I didn't try to use it only with a simple Expo project...

In some cases, certain modules or libraries may not be compatible with Expo or may not be supported within the Expo environment. When facing these limitations, "EAS Build" can be a valuable tool to address these issues.

jole141 avatar Nov 03 '23 14:11 jole141

@JoseOliveira-sensefinity @leodevbro It works for me but with an additional EAS setup and build https://docs.expo.dev/build/setup/

In my project, I've already had EAS setup so It worked, but I didn't try to use it only with a simple Expo project...

In some cases, certain modules or libraries may not be compatible with Expo or may not be supported within the Expo environment. When facing these limitations, "EAS Build" can be a valuable tool to address these issues.

Hi @jole141, How did you? i use bare workflow too but didn't work, doesn't this require an expo module? Can you share the steps with us?

yusufipsum avatar Nov 04 '23 22:11 yusufipsum

@yusufipsum Oh sorry, I've just realized that I started this thread but in the end I've used "react-native-ble-advertise": "^0.4.0", https://github.com/barakataboujreich/react-native-ble-advertise

Usage example (somewhere in my RN code):

const startBeaconAdvertising = useCallback(
    async (uuid: string, major: string, minor: string) => {
      try {
        console.log('[BEACON] - demo started');
        await setCompanyId(parseInt(COMPANY_ID, 16) as any);
        setIsBeaconBroadcasting(true);
        await broadcast(uuid, parseInt(major, 16) as any, parseInt(minor, 16) as any);
        console.log('[BEACON] - Beacon broadcasting started');
      } catch (error) {
        console.log('[BEACON] - Beacon broadcasting error', error);
        setIsBeaconBroadcasting(false);
      }
    },
    [stopBeaconAdvertising]
  );

This library has some "type" problems but with parseInt(major, 16) as any you can do a small workaround.

I don't have time right now, but I'll try to setup a simple Expo project with an EAS build to do a project example.

jole141 avatar Nov 10 '23 08:11 jole141

I have created a simple Expo tutorial: https://github.com/jole141/expo-examples/tree/react-native-ble-advertise

jole141 avatar Nov 23 '23 11:11 jole141

@jole141, Dear Josip, even if this tutorial will turn out to be not fully successful, I still strongly appreciate your effort and your kindness to help us. For sure I am going to try your tutorial very soon.

leodevbro avatar Nov 23 '23 11:11 leodevbro

One question: so, the react-native-ble-advertise library has broadcast feature, but does not have scan feature, right? It would be unfortunate, because I need both.

leodevbro avatar Nov 23 '23 11:11 leodevbro

One question: so, the react-native-ble-advertise library has broadcast feature, but does not have scan feature, right? It would be unfortunate, because I need both.

@leodevbro hello, i am the author of react-native-ble-advertise

no the library doesn't have a ble scanning functionality since i use react-native-ble-manager for ble scanning, and created react-native-ble-advertise for missing functionality in our app.

prior to today i did not know that you can use BLE with Expo, i thought it was only possible through RN CLI. now thanks to @jole141 tutorial, i was able to use both react-native-ble-advertise and react-native-ble-manager in expo

if you are interested i can create a example using both libraries

barakataboujreich avatar Nov 23 '23 15:11 barakataboujreich

if you are interested i can create a example using both libraries

@barakataboujreich, Oh, sure, that would be super I think. I will be super thankful.

leodevbro avatar Nov 23 '23 15:11 leodevbro

@barakataboujreich, Oh, sure, that would be super I think. I will be super thankful.

@leodevbro you can find the tutorial here expo-ble-scan-advertise-example

barakataboujreich avatar Nov 23 '23 16:11 barakataboujreich

Thanks, I'll check it out and do some experiments with it 🚀🚀🚀🚀

leodevbro avatar Nov 23 '23 16:11 leodevbro