Inherits from NSObject
Declared in DTReachability.h

Overview

Block-Based Reachability Observation, using the SystemConfiguration.framework. Based largely on Erica Sadun’s UIDevice Reachability Extension. Modified to use SCNetworkReachabilityCreateWithName instead based on Nick Lockwoods FXReachability because this approach also takes the DNS resolvability into consideration.

A shared instance is provided via defaultReachability which is configured to check reachability of apple.com. Custom reachability manager instances can be configure to monitor reachability of custom host names.

Class Methods

addReachabilityObserverWithBlock:

Adds a block to observe network reachability. Every time the reachability flags change this block is invoked. Also once right after adding the observer with the current state.

+ (id)addReachabilityObserverWithBlock:(DTReachabilityObserverBlock)observer

Parameters

observer

An observation block

Return Value

An opaque reference to the observer which you can use to remove it

Discussion

Warning: use [[DTReachability defaultReachability] addReachabilityObserverWithBlock:]

Declared In

DTReachability.h

defaultReachability

Returns a shared DTReachability instance with the default hostname is apple.com. Generally you should use this because each DTReachability instance maintains its own table of observers.

+ (DTReachability *)defaultReachability

Return Value

the default DTReachability instance

Declared In

DTReachability.h

removeReachabilityObserver:

Removes a reachability observer.

+ (void)removeReachabilityObserver:(id)observer

Parameters

observer

The opaque reference to a reachability observer

Discussion

Warning: use [[DTReachability defaultReachability] removeReachabilityObserver:]

Declared In

DTReachability.h

Instance Methods

addReachabilityObserverWithBlock:

Adds a block to observe network reachability. Every time the reachability flags change this block is invoked. Also once right after adding the observer with the current state.

- (id)addReachabilityObserverWithBlock:(DTReachabilityObserverBlock)observer

Parameters

observer

An observation block

Return Value

An opaque reference to the observer which you can use to remove it

Declared In

DTReachability.h

init

Returns an initialized DTReachability instance with the default hostname: apple.com

- (instancetype)init

Return Value

An initialized DTReachability instance.

Declared In

DTReachability.h

initWithHostname:

Returns an initialized DTReachability instance with a given host name

- (instancetype)initWithHostname:(NSString *)hostname

Parameters

hostname

The host name to monitor

Return Value

An initialized DTReachability instance.

Declared In

DTReachability.h

removeReachabilityObserver:

Removes a reachability observer block from the receiver.

- (void)removeReachabilityObserver:(id)observer

Parameters

observer

The opaque reference to a reachability observer

Declared In

DTReachability.h

setHostname:

Changes the hostname that is monitored for the receiver. All registered observer blocks will be called on reachability changes for the new hostname.

- (void)setHostname:(NSString *)hostname

Parameters

hostname

The new hostname that is monitored

Declared In

DTReachability.h