pusherman / react-native-network-info

React Native library for getting information about the devices network
MIT License
356 stars 106 forks source link

ios 13 Unable to get wifi ssid #105

Closed JayChiuTW closed 4 years ago

JayChiuTW commented 5 years ago

After the mobile phone has been updated to the first version, the SSID of the WIFI can't be obtained normally. Every time it is returned to Wi-Fi, how to solve the problem?

nik-garg commented 5 years ago

After the mobile phone has been updated to the first version, the SSID of the WIFI can't be obtained normally. Every time it is returned to Wi-Fi, how to solve the problem?

You need to ask for user location for getting wifi-ssid in ios 13. Use react native geolocation (https://facebook.github.io/react-native/docs/geolocation.html).

  1. Add the permission in Info.plist ( key : "NSLocationWhenInUseUsageDescription" )
  2. Add a call for requesting user permission to access location ( function to call : geolocation.requestAuthorization() )
redwind commented 5 years ago

it's work only on iphone 6s, ip 6splus, on ip7, wifi ssid still return nill althought location permission is Always. Anyone check this on ip 7 ? Thanks !

memelie commented 5 years ago

Same problem on iPhone6S. I have added Geolocation and asked for permissions which is granted.

memelie commented 5 years ago

Finally got it to work by updating iOS13 to the very last release :)

JayChiuTW commented 5 years ago

@nik-garg I did what you said. I successfully got SSID on the IOS13 system. Thank you very much.

daihieptn97 commented 5 years ago

I did as you said and it doesn't run into the console.log function

Geolocation.requestAuthorization();

          NetworkInfo.getSSID(ssid => {
              console.log(ssid); // not woking
              NetworkInfo.getBSSID(bssid => {
                  if (bssid != "error") {
                      self.setState({ bssidWifi: bssid });
                  }
                  self._getListWifi(ssid, bssid);
              });

              if (ssid != "error") {
                  self.setState({ ssidWifi: ssid });
              } else {
                  Toast.show({
                      text: "Bạn chưa kết nối tới wifi",
                      type: "warning"
                  });
              }
          });

Thanks you!

dmwallace commented 4 years ago

@daihieptn97 it looks like the NetworkInfo.getSSID function now returns a promise rather than taking a callback argument so your code should now be like:

NetworkInfo.getSSID().then(ssid => {…})

or

let ssid = await NetworkInfo.getSSID()

this caught me out too

daihieptn97 commented 4 years ago

@daihieptn97 it looks like the NetworkInfo.getSSID function now returns a promise rather than taking a callback argument so your code should now be like:

NetworkInfo.getSSID().then(ssid => {…})

or

let ssid = await NetworkInfo.getSSID()

this caught me out too

thanks you so much !

shengliZh commented 4 years ago

let ssid = await NetworkInfo.getSSID(); or NetworkInfo.getSSID().then(ssid => {…}) ssid return undefined, why?

JayChiuTW commented 4 years ago

@shengliZh Add the permission in Info.plist ( key : "NSLocationWhenInUseUsageDescription" )

shengliZh commented 4 years ago

image image image I have added this permission, but still get ssid undefined, what should I do?@JayChiuTW

nik-garg commented 4 years ago

image image image I have added this permission, but still get ssid undefined, what should I do?@JayChiuTW

This won't work in a virtual device. Test this in an actual device.

joshbg2k commented 4 years ago

I've added the permission in info.plist, granted location authorization, turned on Allow Wifi Information, and getSSID() returns undefined for me.

iPhone 7 Plus iOS 13.2 React Native 0.55.4 React Native Network Info 5.2.1

memelie commented 4 years ago

According to this post : https://stackoverflow.com/questions/58072820/how-to-get-current-network-information-for-a-given-network-interface-on-ios-13 You need to reboot the device. Worked for me. Not sure it has to do with the package, more with iOS13 itself

joshbg2k commented 4 years ago

@memelie that worked, thanks!