I wanna be clear there’s no such thing as an “active internet connection”, because the Internet is not one thing. The device might think that it has a path to the Internet, and that’ll be reported by NWPathMonitor
, but that doesn’t mean that a network connection to a specific host will work. There are any number of reasons that might fail, many of which are completely out of your control (and the devices’s control, and the user’s control). For example, the host you’re trying to talk to might be offline.
This is a feature that exists in first party Apple apps like the App
Store and also third party apps such as YouTube.
Those apps talk to a specific service and so they can make decisions based on their attempts to connect to that service. That is the approach I recommend. Specifically, if you’re using URLSession
you can sets waitsForConnectivity
, make your request, and then use the urlSession(_:taskIsWaitingForConnectivity:)
delegate callback to drive your UI.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"