Flutter IOS reading wifi name using the connectivity or wifi plugin
Asked Answered
E

1

5

This question is similar this question, but slightly different.

I am trying to retrieve the name of my currently connected wifi network using the Connectivity Plugin.

This answer works perfectly fine in android, and while it sounds like it should work for iOS, I am getting an exception:

PlatformException(UNAVAILABLE, wifi name unavailable, null)

Simple ex. of the code causing the exception (with the assumption I am connected to wifi, also not using an emulator):

Connectivity connectivity = Connectivity();
print(await (connectivity.getWifiName()));

My gut is telling me it may be permission related, but honestly I am not sure.

Cheers and thanks!

Edit:

I just realized, the exception above is thrown by the wifi plugin, which I was also experimenting with.

print(await (Wifi.ssid));

Connectivity simply returns null...

Engelhart answered 16/4, 2019 at 21:18 Comment(1)
apparently it stopped working on iOS12, I'll give it a checkDoherty
D
9

I'll see if I can fix that in the plugin's code. If so, I'll get back to this answer.

However, for now, adding the capability to your project (or simply switching it ON) on Xcode will do it: (no code change in your app required)

# on your project folder, run:
open -a xcode ./ios

In Xcode 12+

On Target > Runner > Signing & Capabilities, use the + Capability button to add the Access WiFi Information capability to your project.

adding capability

In older Xcode versions

On Runner > Capabilities, switch Access WiFi Information to on.

See:

switching WiFi information ON

Doherty answered 17/4, 2019 at 16:58 Comment(3)
Thank you for looking at this!Engelhart
In my case I am only I am not able to see this on/off switch button. Can anybody let me know that how can I access it.Benjie
in my case it's still return nullLuckless

© 2022 - 2024 — McMap. All rights reserved.