PadraigK / JTSReachability

Adaptation of Apple's Reachability with some block-based conveniences.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JTSReachability

An adaptation of Apple's Reachability with some block-based conveniences.

Usage

Usage is straightforward.

Singleton

Access the singleton instance of JTSReachabilityResponder via:

+ (instancetype)sharedInstance;

Or Non-Singleton, if You're Not Into the Whole Singleton Thing

Instantiate an instance of JTSReachabilityResponder via:

- (instancytype)initWithOptionalHostname:(NSString *)hostname;

If you don't specify a hostname, there are some edge cases where Apple's networking frameworks will assume there's a valid connection even when there isn't (e.g. when connected to a local WiFi network without a connection to the Internet proper).

Registering Status Change Handlers

An object in your application registers a block to be executed whenever the network status changes between one of the three known states (none, Wi-fi, or cellular) as follows:

- (void)someSetupMethod {

    JTSReachabilityResponder *responder = [JTSReachabilityResponder sharedInstance];
    
    [responder addHandler:^(JTSNetworkStatus status) {
        // Respond to the value of "status"
    } forKey:@"MyReachabilityKey"];
} 

Your object is responsible for cleaning up after itself, typically in dealloc, as follows:

- (void)dealloc {

    JTSReachabilityResponder *responder = [JTSReachabilityResponder sharedInstance];
    
    [responder removeHandlerForKey:@"MyReachabilityKey"];
}

All blocks are called on the main thread, and must be added or removed on the main thread.

About

Adaptation of Apple's Reachability with some block-based conveniences.

License:MIT License


Languages

Language:Objective-C 94.9%Language:Ruby 5.1%