CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Nov 2017 |
Maintained by Abizer Nasir.
#NPReachability
NPReachability is an evolution of Apple's Reachability class that provides
information about the network status.
As well as supporting the original's Notification based monitoring, this class
supports both KVO and Blocks, so you can choose whichever way of handling
changes as your application requires.
This class is written as a singleton, so be sure to reference it as
NPReachability *reachability = [NPReachability sharedInstance];
Make sure you maintain a strong reference to at least one object of this class
or else ARC will clean it up underneach you.
Handlers are declared as
typedef void (^ReachabilityHandler)(NPReachability *curReach);
This takes the NPReachability object as a parameter. As originally written
this class passed the SCNetworkReachabilityFlags
as a parameter, but you can
get that and more by messaging the object directly
You add blocks to be executed when the network status changes by using:
- (id)addHandler:(ReachabilityHandler)handler;
This returns an opaque object which you should use to remove the handler at the
appropriate time (in a dealloc
, say) with:
- (void)removeHandler:(id)opaqueObject;
Two properties can observed for changes to the network status:
@property (nonatomic, readonly, getter=isCurrentlyReachable) BOOL currentlyReachable;
@property (nonatomic, readonly) SCNetworkReachabilityFlags currentReachabilityFlags;
When the network status changes a NPReachabilityChangedNotification
is sent
with the NPReachability instance as the notification object.
Add the project as a submodule to your project's repository and add the
NPReachability.h
and NPReachability.m
files to your project.
This is also available as a CocoaPod. If you're a Podder, then you already know
what to do to add this to your project.
Just add the NPReachability.h
and NPReachability.m
files to your
project. But I think the other any of the previous two methods is preferable to
this.
Apple provided the Reachability Sample Code to demonstrate the use of their
Reachability
class. To see how to use this Class instead have a look at
NPReachability-Example
which shows the same project using NPReachability
instead.
Please use and improve! Patched accepted, or create an issue.
I'd love it if you could send me a note as to which app you're using it with!