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.

The SCNetworkReachability programming interface supports a synchronous and an asynchronous model. In the synchronous model, you get the reachability status by calling the SCNetworkReachabilityGetFlags(_:_:) function. In the asynchronous model, you can schedule the SCNetworkReachability object on the run loop of a client object’s thread. The client implements a callback function to receive notifications when the reachability status of a given remote host changes. Note that these functions follow Core Foundation naming conventions. A function that has "Create" or "Copy" in its name returns a reference you must release with the CFRelease function.

For information about detecting and interpreting errors generated by calling these functions, see System Configuration.


Creating a Reachability Reference

func SCNetworkReachabilityCreateWithAddress(CFAllocator?, UnsafePointer<sockaddr>)

Creates a reachability reference to the specified network address.

func SCNetworkReachabilityCreateWithName(CFAllocator?, UnsafePointer<Int8>)

Creates a reachability reference to the specified network host or node name.

Determining Reachability Status

func SCNetworkReachabilityGetFlags(SCNetworkReachability, UnsafeMutablePointer<SCNetworkReachabilityFlags>)

Determines if the specified network target is reachable using the current network configuration.

Preparing to Determine Reachability

func SCNetworkReachabilityGetTypeID()

Returns the type identifier of all SCNetworkReachability instances.

func SCNetworkReachabilitySetCallback(SCNetworkReachability, SCNetworkReachabilityCallBack?, UnsafeMutablePointer<SCNetworkReachabilityContext>?)

Assigns a client to the specified target, which receives callbacks when the reachability of the target changes.

func SCNetworkReachabilityScheduleWithRunLoop(SCNetworkReachability, CFRunLoop, CFString)

Schedules the specified network target with the specified run loop and mode.

func SCNetworkReachabilityUnscheduleFromRunLoop(SCNetworkReachability, CFRunLoop, CFString)

Unschedules the specified target from the specified run loop and mode.

func SCNetworkReachabilitySetDispatchQueue(SCNetworkReachability, DispatchQueue?)

Schedules callbacks for the specified target on the specified dispatch queue.


typealias SCNetworkReachabilityCallBack

Type of callback function used when the reachability of a network address or name changes.

Data Types

class SCNetworkReachability

The handle to a network address or name.

struct SCNetworkReachabilityContext

Structure containing user-specified data and callbacks used with SCNetworkReachabilitySetCallback(_:_:_:).


struct SCNetworkReachabilityFlags

Flags that indicate the reachability of a network node name or address, including whether a connection is required, and whether some user intervention might be required when establishing a connection.