Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native Wifi reborn (WifiManager) issue on iOS (working fine on Android) #413

Open
hussnainshafiul opened this issue Dec 19, 2024 · 3 comments

Comments

@hussnainshafiul
Copy link

hussnainshafiul commented Dec 19, 2024

I am using the react-native-wifi-reborn library to connect to a Wifi Network from the App without going into Wifi Settings. The code is working fine on android but on IOS it gives an error:

" Argument 4 (NSNumber) of WifiManager.connectToProtectedSSID is marked as nullable but React requires that all NSNumber arguments are explicitly marked as nonnull to ensure compatibility with Android. "

Screenshot 2024-12-19 at 5 56 10 PM

`import React from 'react';
import {View, Text, Button, Alert, StyleSheet} from 'react-native';
import WifiManager from 'react-native-wifi-reborn';

const App = () => {

const ssid = '';
const password = '';

const connectToWifi = async () => {
await WifiManager.connectToProtectedSSID(ssid, password, false, true);
console.log(Connected to Wi-Fi: ${ssid});
};

return (

Connect to Local Network


);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
title: {
fontSize: 20,
fontWeight: 'bold',
marginBottom: 20,
},
});

export default App;
`

"react-native-wifi-reborn": "^4.12.1",
"react-native": "0.74.2",

@DavideViolante
Copy link
Collaborator

DavideViolante commented Dec 19, 2024

Try to upgrade to v4.13.0, that issue should be fixed already. Duplicate of #379

@nikodunk
Copy link
Contributor

nikodunk commented Dec 21, 2024

I am on 4.13.0 and it's still present there. Adding a 5th timeout argument on iOS works for me.

     if (Platform.OS === 'ios') {
        WifiManager.connectToProtectedSSID(ssid, password, false, false, 5000).then(
          () => {
            console.log("Connected successfully!");
          },
          () => {
            console.log("Connection failed!");
          }
        );
      }
      if (Platform.OS === 'android') {
        WifiManager.connectToProtectedSSID(ssid, password, false, false).then(
          () => {
            console.log("Connected successfully!");
          },
          () => {
            console.log("Connection failed!");
          }
        );
      }

The JSDoc conflicts with the docs (README) on this one I believe?

image

vs.

connectToProtectedSSID(
   SSID: string, 
   password: string, 
   isWEP: boolean, 
   isHidden: boolean, 
   timeout: number
): Promise

from here?

Have I misunderstood something or should I open a PR to update the docs @DavideViolante ?

@DavideViolante
Copy link
Collaborator

DavideViolante commented Dec 30, 2024

The readme was wrong due to this PR that introduced 2 very similar methods: #355
I fixed the readme, in short you can use the timeout param only with the connectToProtectedWifiSSID method and only on android, afaik, and the params of the method is an object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants