Latest 0.0.1
Homepage https://github.com/liufan321/NetReachability
License MIT
Platforms ios 8.0, requires ARC
Authors

Just use one simple func to check the reachability to specified host.

Requirements

  • iOS 8.0+
  • Xcode 7.0 beta
  • Swift 2.0

CocoaPods

CocoaPods 0.38 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

To integrate NetReachability into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'NetReachability'

Then, run the following command:

$ pod install

You should open the {Project}.xcworkspace instead of the {Project}.xcodeproj after you installed anything from CocoaPods.

For more information about how to use CocoaPods, I suggest this tutorial.

Usage

  • define reachability variable
private lazy var reachability: NetReachability = NetReachability(hostname: "www.baidu.com")
  • add notification
NSNotificationCenter.defaultCenter().addObserver(self, selector: "statusChanged", name: FFReachabilityChangedNotification, object: nil)
reachability.startNotifier()
  • remove notification
reachability.stopNotifier()
NSNotificationCenter.defaultCenter().removeObserver(self, name: FFReachabilityChangedNotification, object: nil)
  • observer func
func statusChanged() {
    print(reachability.currentReachabilityStatus)
}

Refrence

https://developer.apple.com/library/ios/samplecode/Reachability/Reachability.zip

Latest podspec

{
    "name": "NetReachability",
    "version": "0.0.1",
    "summary": "Check Internet Reachability in Swift",
    "homepage": "https://github.com/liufan321/NetReachability",
    "license": "MIT",
    "authors": {
        "Fan Liu": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/liufan321/NetReachability.git",
        "tag": "0.0.1"
    },
    "source_files": "Source/*.swift",
    "requires_arc": true
}

Pin It on Pinterest

Share This