Expo: 'react-native-wifi-reborn' lib is not working

Viewed 566

I use react-native-wifi-reborn in my react-native application (expo); App is configured according to official docs

I need to connect to a specified wifi network with predifined ssid and password.

import WifiManager from 'react-native-wifi-reborn';

const onClickConnect = async (ssid: string) => {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
      {
        title: 'Location permission is required for WiFi connections',
        message:
          'This app needs location permission as this is required  ' +
          'to scan for wifi networks.',
        buttonNegative: 'DENY',
        buttonPositive: 'ALLOW',
      },
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      WifiManager.connectToProtectedSSID('test-wifi', 'password', false)
        .then(() => console.log("connectToProtectedSSID successfully!"));
    } else {
      console.log('Permission denied');
    }
  }

However, I get an error for each WifiManager method

[Unhandled promise rejection: TypeError: null is not an object (evaluating '_reactNativeWifiReborn.default.connectToProtectedSSID')]
at http://192.168.1.100:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:151908:46 in onClickConnect$

I have found some suggestions to clean expo cache or re-install node-modules but that did not help. Please help! Deadline is coming... :(

0 Answers
Related