[英]Swift: How to check if my app has WLAN permission and the device is connected to a WIFI source?
I'm developing an app in which I need to know: 我正在开发一个我需要知道的应用程序:
I know you can use Reachability to check if the device is connected to the internet, but it return true even if the app doesn't has the permission to access network. 我知道你可以使用Reachability来检查设备是否已连接到互联网,但即使应用程序没有访问网络的权限,它也会返回true。 How can I know the 2 information I listed above ?
我怎么知道上面列出的2个信息?
Additional information: This is not a regular app. 附加信息:这不是常规应用程序。 This app is used to control a toy via WIFI.
此应用程序用于通过WIFI控制玩具。 So I don't really care if the app is connected to the internet.
所以我真的不在乎应用是否连接到互联网。 All I want to know is if the app has the permission to access WLAN network.
我想知道的是,该应用程序是否具有访问WLAN网络的权限。
If you are worried that there may be a captive portal giving a false "connected" status to Reachability then you need to attempt to retrieve a known piece of data from a known website; 如果您担心可能存在强制门户网站给可达性提供错误的“连接”状态,那么您需要尝试从已知网站检索已知数据; then if you get the expected result you can be fairly confident that your app has network access.
然后,如果您获得预期的结果,您可以相当确信您的应用程序具有网络访问权限。
For example, http://captive.apple.com returns: 例如, http : //captive.apple.com返回:
<HTML>
<HEAD>
<TITLE>Success</TITLE>
</HEAD>
<BODY>
Success
</BODY>
</HTML>
This is the web site that iOS and macOS attempt to access in order to determine whether the hotspot login helper window should be shown. 这是iOS和macOS尝试访问的网站,以确定是否应显示热点登录帮助窗口。
If iOS doesn't get the expected "success" (as is the case if all access is redirected to a "login" screen) or the connection times out then the helper window is shown. 如果iOS未获得预期的“成功”(如果所有访问都被重定向到“登录”屏幕)或连接超时,则显示帮助程序窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.