Expo react-native-wifi-reborn connectToProtectedSSID Error on iOS - Stack Overflow

I'm developing my first expo project and am using the library react-native-wifi-reborn to connect

I'm developing my first expo project and am using the library react-native-wifi-reborn to connect to a web server created by an IOT device (ESP-32) and send over a binary file. The code works perfectly on android, but on iOS, I get this error:

connectToProtectedSSID(): Tried to resolve promise multiple times

I think it has something to do with iOS detecting the WiFi doesn't have internet connection and tries to reconnect to another network or retry.

I also get this error later on, during my upload file function where I use ReactNativeBlobUtil to send over the binary file:

Error: The network connection was lost

Here is my code to connect to the webserver:

const connectToWebServer = async () => {
    const currentWifiSSID = await WifiManager.getCurrentWifiSSID();
    try {
      let wifiList: WifiEntry[];
      let ssidExists: boolean | null = null;
      if (ExpoDevice.osName === "Android") {
        wifiList = await WifiManager.reScanAndLoadWifiList(); //Not on iOS

        ssidExists = wifiList.some((wifi) => wifi.SSID.trim() === OTA_SSID);
      }

      // console.log("ssidExists: ", ssidExists);

      if (ssidExists || ExpoDevice.osName === "iOS") {
        const initialSSID = await WifiManager.getCurrentWifiSSID();
        if (ExpoDevice.osName === "iOS") {
          await WifiManager.disconnectFromSSID(initialSSID);
          await WifiManager.connectToProtectedSSID(
            OTA_SSID,
            null,
            false,
            false
          );
          await delay(2000);
        } else {
          await WifiManager.disconnect();
          await WifiManager.connectToProtectedSSID(
            OTA_SSID,
            null,
            false,
            false
          );
        }

        const newSSID = await WifiManager.getCurrentWifiSSID();
        console.log("newSSID: ", newSSID);
        if (newSSID === OTA_SSID) {
          console.log("Setting is connected to Web Server: True");
          setIsConnectedToWebServer(true);
        }
      } else {
        console.error(
          "Setting is connected to Web Server: False(newSSID !== OTASSID)"
        );
        setIsUpdateError(true);
        setIsConnectedToWebServer(false);
        throw new Error("SSID doesn't exist!");
      }
    } catch (error) {
      setIsUpdateError(true);
      setIsConnectedToWebServer(false);
      console.error(
        "Setting is connected to Web Server: False(Error)",
        JSON.stringify(error)
      );
    } finally {
      setIsConnectingToWebServer(false);
    }
  };

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745098200a4611110.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信