Reachability.swift: Reachability(hostname: host) does not work

My IPad is connected to an Wifi hotspot without any connection to the internet. If I try this code, I receive true.

let host = "www.google.com"
let reachability: Reachability
do {
    reachability = try Reachability(hostname: host)
    nwAvailable = reachability.isReachableViaWiFi()
} catch {
    ...
}

If the hotspot has internet or the wifi is disconnected, the code works very well.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 4
  • Comments: 22 (2 by maintainers)

Most upvoted comments

I don’t think you can fix it while using the SCNetworkReachability interface. From the SCNetworkReachability Apple docs:

The SCNetworkReachability programming interface allows an application to determine the status of a system’s current network configuration and the reachability of a target host. A remote host is considered reachable when a data packet, sent by an application into the network stack, can leave the local device. Reachability does not guarantee that the data packet will actually be received by the host.

You’d have to be able to send something to the remote host and get a response to cover this edge case. Something like a ping or small network request. That’s not a perfect solution either as some router configurations block incoming pings.

Up!

how to monitor internet checking in this case:- I have connected to WIFI but ,i turned off my internet connection,in this case notify method is not calling