Your device may connect to a wireless AP via Wi-Fi but the AP's cable is unplugged, or it may connect to a base station but your service provider stop working for some reasons. What's the easiest way to know current network status? CHTReachability tries to detect REAL network reachability for you.
- Easy to use.
- Highly customizable.
- ARC
- iOS 8+
It uses Apple's Reachability and SimplePing sample codes to do the real works.
- First it uses Reachability to check network reachability.
- When network status is
Reachable
then it uses SimplePing to ping specified host. - The status changes from
Reachable
toOnline
if it receives packet.
You can use CocoaPods to install CHTReachability
by adding it to your Podfile
:
platform :ios, '8.0'
# If you're using Swift, remember to `use_frameworks!`
use_frameworks!
pod 'CHTReachability'
To get the full benefits import CHTReachability
wherever you import UIKit
import UIKit
import CHTReachability
#import <CHTReachability/CHTReachability.h>
- Copy
CHTReachability.h/m
to your project. - Copy
Vender
folder to your project. - Add
SystemConfiguration.framework
.
Check the demo codes and CHTReachability.h
header file for more information.
- (void)viewDidLoad {
[super viewDidLoad];
self.reach = [[CHTReachability alloc] initWithHostName:CHTReachabilityDefaultPingHostName delegate:self];
}
#pragma mark - <CHTReachabilityDelegate>
- (void)reachability:(CHTReachability *)reachability didChangeToStatus:(CHTReachabilityStatus)status {
NSLog(@"Status = %@", @(status));
}
CHTReachability is available under the MIT license. See the LICENSE file for more info.
Refer to the releases page.