简体   繁体   English

Swift:如何检查我的应用是否具有WLAN权限并且设备是否已连接到WIFI源?

[英]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: 我正在开发一个我需要知道的应用程序:

  1. Does my app has the permission to access WLAN network. 我的应用是否拥有访问WLAN网络的权限。
  2. Is the device currently connected to a WIFI. 设备当前是否已连接到WIFI。

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.

相关问题 如何快速检查wifi上的受限访问权限,例如我的设备已连接到wifi,但该wifi没有互联网连接 - How to check the Limited Access on wifi in swift, like if my device is connected to wifi but that wifi don't have internet connection 如何在设备连接到网络(wifi / 3G)时检查互联网连接,但在使用Swift的iOS中没有互联网访问? - How to check for internet connectivity when device is connected to a network (wifi/3G) but there is no internet access in iOS using Swift? 检查外部ble设备是否仍然快速连接到应用程序的最佳方法 - Best way to check the external ble device is still connected to app in swift 如何在iPhone上检查wifi服务以在我的应用中使用wifi导航 - how to check wifi service on iPhone for uses wifi navigation in my app Flutter 如何检查是否有设备通过蓝牙连接到我的设备 - Flutter how to check if there is a device connected to my device via bluetooth 如何检查本地WiFi网络中的设备是否已使用其IP地址连接? - How to check whether a device in local WiFi network is connected or not using it's IP address? 在 Swift2 中检查设备是否已连接到互联网 - Check if device is connected to the internet in Swift2 当应用程序在我的设备(iPhone 6)上快速运行时,“没有可用的源1类型” - 'No available types for source 1' when the app runs on my device(IPhone 6) swift 是否可以检查WiFi是否已连接但是Swift中没有使用可达性的互联网连接? - Is it possible to check if WiFi is connected but there is no internet connection in Swift using Reachability? iOS:在应用程序处于后台时监控连接到Wifi设备的套接字 - iOS: Monitor a Socket Connected to a Wifi Device while app is in Background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM