Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28469

Wait till reScanAndLoadWifiList returns available wifi networks in react-native

$
0
0

I am using react-native-android-wifi library in my react-native project for fetching available WiFi networks, here's what I am doing currently,

1. Check if wifi is enabled or not, if not then enable it

  wifi.isEnabled(isEnabled => {
    if (!isEnabled) {
      wifi.setEnabled(true);
    }
  });

2. Fetch all nearby WiFi networks available and show it to the screen

  wifi.reScanAndLoadWifiList(
    wifiStringList => {
      var wifiArray = JSON.parse(wifiStringList);
      console.log("Detected wifi networks - ", wifiArray);
    },
    error => {
      console.log(error);
    }
  );

Here the issue which I am facing is, the first time wifiStringList returns an empty array, but if I try refreshing, then it gives me list of WiFi's. How can I wait till wifiStringList has the list of available WiFi's. I know putting a setTimeout of around 3-5 secs will solve the issue, but I want to know what's the other approach rather than using setTimeout. Please tell me how can I achieve the desired result? Thanks a lot.


Viewing all articles
Browse latest Browse all 28469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>