Easiest way to detect Internet connection on iOS?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
On modern iOS, the easiest way to observe network availability is NWPathMonitor from the Network framework. It tells you whether the device currently has a usable network path, which is much better than older reachability patterns, but it still does not guarantee that your specific server is reachable.
Use NWPathMonitor for Reachability State
NWPathMonitor gives you a stream of path updates as the network changes. You can inspect whether the path is satisfied and whether the connection is using Wi-Fi, cellular, or another interface.
This is usually enough to show offline UI, disable sync buttons temporarily, or decide whether to retry queued work.
Understand What It Does Not Tell You
NWPathMonitor answers "does the device currently have a usable network path?" It does not answer "is my backend healthy?" or "can I reach this exact URL?" Those are application-level questions, and the only reliable way to answer them is to make a real request.
For example, if your app depends on one API, pair reachability state with an actual probe or the normal request flow:
This second step matters because a device may be online while your API is down, blocked, or misconfigured.
Update the UI Safely
NWPathMonitor callbacks do not arrive on the main thread, so any UI work must be dispatched back to the main queue. That is why the example above wraps the callback with DispatchQueue.main.async.
In a UIKit controller, a simple usage pattern looks like this:
This keeps the reachability logic separate from the view code and avoids stale callbacks.
Prefer Observation Over Gating
One common mistake is blocking every network request until a reachability monitor reports "online." In practice, the network state can change between the time you check it and the time the request is sent. A more robust design is:
- observe connectivity for user experience
- attempt the request anyway
- handle the real request error cleanly
That pattern produces better apps because it does not rely on reachability as a perfect predictor.
Common Pitfalls
- Treating
NWPathMonitoras proof that your backend is reachable. It only reports path availability on the device. - Updating UI directly from the path callback without hopping back to the main thread.
- Forgetting to keep the monitor alive. If it is deallocated immediately, you will never receive updates.
- Using reachability as a hard gate before every request instead of handling actual request failures.
- Relying only on the simulator. Cellular, captive portal, and real network transitions are much easier to validate on a device.
Summary
- On modern iOS,
NWPathMonitoris the simplest built-in way to observe connectivity changes. - Use it to drive UI and retry behavior, not as a guarantee that your server is healthy.
- Make a real request when you need to know whether a specific endpoint is reachable.
- Dispatch UI updates back to the main queue.
- Treat connectivity checks as helpful signals, not as a substitute for proper network error handling.
Related reading
- Easiest way to post to a server on iPhone? I don't care about the response
- Easy way to see saved NSUserDefaults?
- Eclipse hangs at the Android SDK Content Loader
- edit-config for ios usage descriptions doc.find is not a function
- Editing screenshots in iTunes Connect after iOS app was approved
- ektorp couchDB to android replication
- Eliminate extra separators below UITableView
- Email Address Validation in Android on EditText
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.