How to use SCNetworkReachability in Swift
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
SCNetworkReachability is a low-level Apple API for observing whether a route to a host or address appears reachable. It is useful for network-awareness features, but it does not prove that your server is healthy or that the internet is truly usable.
What the API Actually Tells You
The SystemConfiguration framework exposes SCNetworkReachability as a C-based API. In Swift, you usually wrap it in a small class so you can read flags and respond to changes more comfortably.
At a high level, the API answers questions such as:
- is a route currently reachable
- does a connection need to be established first
- is the route currently using cellular on supported platforms
That is narrower than "the app can successfully call my backend." A captive portal, broken DNS, or server outage can still make requests fail even when reachability says a route is available.
Reading the Current Reachability Flags
The example below creates a reachability reference for a host and reads its current flags.
The common quick check is reachable && !connectionRequired. That gives a reasonable "probably usable" signal for many apps.
Listening for Reachability Changes
Polling flags occasionally works, but callbacks are usually better when the app needs to react to transitions.
Usage:
Keep a strong reference to monitor. If it is deallocated, your callback logic disappears too.
Interpreting Flags Carefully
Reachability flags are hints, not a guarantee of successful traffic. For example, a route can be marked reachable while your actual API call still fails because the server is down or TLS negotiation breaks.
Also remember that isWWAN is a platform-specific flag and is primarily relevant on iOS. Do not build core network logic around that flag unless you have a concrete product reason.
When to Prefer NWPathMonitor
For newer Apple platforms, NWPathMonitor from the Network framework is often a friendlier API. It provides a higher-level view of path status and interface type. SCNetworkReachability still matters in legacy code and low-level integrations, but new applications often choose NWPathMonitor unless they specifically need the older API.
Common Pitfalls
The biggest pitfall is treating reachability as proof that the internet works. The only true proof is a real request to the service you care about.
Another issue is failing to retain the monitor object. If the wrapper is created in a local scope and then released, callbacks stop without much explanation.
Be careful to stop monitoring when appropriate. Leaving callbacks attached forever can complicate object lifecycle management.
Summary
- '
SCNetworkReachabilityreports route reachability flags, not guaranteed end-to-end connectivity.' - In Swift, wrap the C API in a small class to read flags and handle callbacks safely.
- A common reachability check is
reachable && !connectionRequired. - Keep the monitor alive and detach it when you no longer need updates.
- Consider
NWPathMonitorfor newer apps unless you specifically needSCNetworkReachability.
Related reading
- How to use Session Affinity on requests to Kubernetes service?
- How to use SSH to run a local shell script on a remote machine?
- How to use Tensorflow addons' metrics correctly in functional API?
- How to use Tensorflow dataset API with training and validation sets
- How to use ScrollView in Android?
- How to use SharedPreferences in Android to store, fetch and edit values
- How to use tfa.seq2seq.BahdanauAttention with tf.keras functional API?
- How to use ThreeTenABP in Android Project

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.