Skip to content

_reactNativeWifiReborn.default. "forceWifiUsageWithOptions" is not a function (it is undefined) #428

Closed
@mandrillxx

Description

@mandrillxx

Code snippet:

const connectToWifi = useCallback(async () => {
    try {
      setState((prev) => ({ ...prev, step: "connecting" }));

      // Check network permissions and state
      const networkState = await Network.getNetworkStateAsync();
      if (!networkState.isConnected) {
        throw new Error("Please enable Wi-Fi to continue");
      }

      try {
        // Attempt to connect to the network
        await WifiManager.connectToProtectedWifiSSID({
          ssid: CONFIG.ssid,
          password: CONFIG.password,
          isWEP: false,
          isHidden: false,
          timeout: 30
        });
      } catch (error) {
        // Handle WiFi connection errors immediately
        if (error instanceof Error) {
          if (error.message.includes("locationPermissionMissing")) {
            throw new Error("Location permission is required to connect to Wi-Fi");
          } else if (error.message.includes("locationServicesOff")) {
            throw new Error("Please enable location services to connect to Wi-Fi");
          } else if (error.message.includes("timeoutOccurred")) {
            throw new Error("Connection timed out. Please try again");
          } else if (error.message.includes("android10ImmediatelyDroppedConnection")) {
            throw new Error("Connection dropped. This may be due to a device firmware issue");
          } else if (error.message.includes("authenticationErrorOccurred")) {
            throw new Error("Failed to authenticate with the network. Please check the password");
          } else {
            throw error;
          }
        }
        throw new Error("Failed to connect to dashcam network");
      }

      // Only proceed with force WiFi and verification if connection succeeded
      await WifiManager.forceWifiUsageWithOptions(true, { noInternet: true });

      // Verify we're connected to the correct network
      const connectedSSID = await WifiManager.getCurrentWifiSSID();
      if (connectedSSID === CONFIG.ssid) {
        setState((prev) => ({
          ...prev,
          step: "pairing",
          ssid: connectedSSID,
        }));
        completePairing();
      } else {
        throw new Error("Connected to wrong network");
      }
    } catch (error) {
      // Make sure to disable forced WiFi usage on error
      if (Platform.OS === 'android') {
        try {
          await WifiManager.forceWifiUsageWithOptions(false, { noInternet: true });
        } catch {
          // Ignore cleanup errors
        }
      }

      // Show error immediately
      handleError(error instanceof Error ? error.message : "Failed to connect to dashcam");
    }
  }, [handleError, completePairing]);

The above produces _reactNativeWifiReborn.default. "forceWifiUsageWithOptions" is not a function (it is undefined)
iOS 18.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions