Flutter IOS使用连接性或wifi插件读取wifi名称 [英] Flutter IOS reading wifi name using the connectivity or wifi plugin
问题描述
这个问题与这个问题,但略有不同.
This question is similar this question, but slightly different.
我正在尝试使用连接插件来检索当前连接的wifi网络的名称.
I am trying to retrieve the name of my currently connected wifi network using the Connectivity Plugin.
此答案在android上运行良好,虽然听起来像应该在iOS上正常工作,但我得到了例外:
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)
简单的例子.导致异常的代码(假设我已连接到wifi,也未使用模拟器):
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.
干杯,谢谢!
我刚刚意识到,上述异常是由 wifi插件抛出的.也正在尝试.
I just realized, the exception above is thrown by the wifi plugin, which I was also experimenting with.
print(await (Wifi.ssid));
连接性仅返回null ...
Connectivity simply returns null...
推荐答案
我将看看是否可以在插件代码中对其进行修复.如果是这样,我会回到这个答案.
I'll see if I can fix that in the plugin's code. If so, I'll get back to this answer.
但是,目前,只需在Xcode上切换此ON
即可:(无需在您的应用中更改任何代码)
However, for now, simply switching this ON
on Xcode will do it: (no code change in your app required)
# on your project folder, run:
open -a xcode ./ios
在Runner > Capabilities
上,将Access WiFi Information
切换到on
.
请参阅:
这篇关于Flutter IOS使用连接性或wifi插件读取wifi名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!