Swift: How to check if my app has WLAN permission and the device is connected to a WIFI source?

后端 未结 1 1409
我寻月下人不归
我寻月下人不归 2021-01-14 11:11

I\'m developing an app in which I need to know:

  1. Does my app has the permission to access WLAN network.
  2. Is the device currently connected to a WIFI.
相关标签:
1条回答
  • 2021-01-14 11:33

    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:

    <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.

    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.

    0 讨论(0)
提交回复
热议问题