In my React-Native application I want to scan Bluetooth Beacon when app is closed

264 Views Asked by At

I want to scan Bluetooth in app kill mode. I don't need to connect the device just scan, It's working in background mode I am using react-native-ble-plx plugin

I am trying to scan Bluetooth when React native application is closed

useFocusEffect(
    useCallback(() => {
      //const manager = new BleManager();
      const manager = new BleManager();
      const subscription = manager.onStateChange((state) => {
        if (state === "PoweredOn") {
          manager.startDeviceScan(
            ["0000feaa-0000-1000-8000-00805f9b34fb"],
         
            { allowDuplicates: true, ScanMode: ScanMode.LowLatency },
            (error, device) => {
              if (error) {
                console.log("scaned device-error", error);
                // Handle error (scanning will be stopped automatically)
                return;
              }
              beaconAction(device);
            }
          );
          return () => {
            subscription.remove();
            manager.stopDeviceScan();
          };`
        }
      }, true);
    }, [])
  );
0

There are 0 best solutions below