Latest1.0.1
Homepagehttps://github.com/a-snail/NOCReachability
LicenseMIT
Platformsios 9.0, requires ARC
DependenciesNOCLog
Authors

Build Status
Version
Platform
License
Twitter

NOCReachability is a library that provides functions for checking the status of network connections.

Installation

You can install it using CocoaPods, the project dependency management tool using Objective-C and Swift.

Installation with CocoaPods

To inject a NOCReachability dependency into your Xcode project using CocoaPods, add NOCReachability in the Podfile.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

target 'YourProjectName' do
  pod 'NOCReachability', '~> 1.0'
end

If you are already using a Podfile, you only need to add the NOCReachability dependency.

pod 'NOCReachability', '~> 1.0'

If the NOCReachability dependency is added to the Podfile, execute the following command.

$ pod install

Usage

NOCReachability is a singleton pattern, and you can use singleton objects with the NOCReachability.sharedInstance property.

Network connection status

Connection statusNOCReachabilityStatusExplanation
-1NOCReachabilityStatusUnknownThe status of the network connection is unknown.
0NOCReachabilityStatusNotReachableThe network is not connected.
1NOCReachabilityStatusReachableViaWWANThe status of the network connection using the mobile network(Cellular).
2NOCReachabilityStatusReachableViaWiFiThe status of the network connection using the WiFi.

Check current network connection status

You can simply check the code below.

NOCReachabilityStatus status = NOCReachability.sharedInstance.status;

If you use the [NOCReachability.sharedInstance statusToString] method, you can check the network status as a string rather than a constant.

NSString *status = [NOCReachability.sharedInstance statusToString];

Network connection state change detection

If the network status of the device changes, you can set the code block to be executed and perform the desired operation if the network is changed.

NOCReachability *reachability = NOCReachability.sharedInstance;
[reachability setStatusChangeBlock:^(NOCReachabilityStatus status) {
    // A code block that to be executed when the network state changes.
}];
[reachability startMonitoring];

If you want to stop detecting network state changes started with the above code, you can stop it with the following code.

[NOCReachability.sharedInstance stopMonitoring];

Monitoring network changes using the NotificationCenter

If you started monitoring network changes using the [NOCReachability.sharedInstance startMonitoring] method, you can also perform the desired action if the network changes by using a notification reception instead of a code block.

If the network changes, the name of the notification delivered is NOCReachabilityDidChangeNotification.

If the device’s network changes and a NOCReachabilityDidChangeNotification notification is sent, the changed network state is passed to theuserInfo object of the notification object with the value of NOCReachabilityNotificationStatus.

License

NOCReachability is released under the MIT license.
See LICENSE for details.

Latest podspec

{
    "name": "NOCReachability",
    "version": "1.0.1",
    "summary": "NOCReachability is a library that provides features for checking network status.",
    "homepage": "https://github.com/a-snail/NOCReachability",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jaeo Bok": "[email protected]"
    },
    "social_media_url": "https://twitter.com/snail_bok",
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/a-snail/NOCReachability.git",
        "tag": "1.0.1"
    },
    "source_files": "NOCReachability/*.{h,m}",
    "dependencies": {
        "NOCLog": [
            "~> 1.0"
        ]
    }
}

Pin It on Pinterest

Share This