Latest 0.0.2
Homepage https://github.com/ymsheng/ReachabilitySwift
License MIT
Platforms ios 8.0
Frameworks Foundation, UIKit
Authors

We need to abserve the Real reachability of network for iOS. But Reachability only check your device is connect by wifi or wwan, MNReachabilitySwift do the real jobs.

Apple doc tells us something about SCNetworkReachability API: "Note that reachability does not guarantee that the data packet will actually be received by the host."

MNReachabilitySwift contains two step:
  1. check your device connect by wifi or wwan
  2. try connect to "www.baidu.com" and judge if the server has response

How To User:

import MNReachabilitySwift
MNReachability.sharedInstance.startNotifier() //start test
NSNotificationCenter.defaultCenter().addObserver(self, selector: "networkChanged:", name: kRealReachabilityChangedNotification, object: nil)
func networkChanged(notification:NSNotification) {
let reachability:MNReachability = notification.object as! MNReachability
let status:ReachabilityStatus = reachability.currentReachabilityStatus()

    if status == ReachabilityStatus.ReachStatusNotReachable {
        print("network unreachable")
    }
    else if status == ReachabilityStatus.ReachStatusViaWiFi {
        print("network wifi! Free")
    }
    else if status == ReachabilityStatus.ReachStatusViaWWAN {
        print("network WWAN! In charge")
    }
}

Quick Start With Cocoapods

1.Use Code Direct
Download the project, add swift file in MNReachability to your project.

2.Use CocoaPods Install

platform :ios, "8.0"

use_frameworks!

pod ‘MNReachabilitySwift’, ‘~> 0.0.2’

了解CocoaPods
http://ymsheng.github.io/cocoapods.html

Latest podspec

{
    "name": "MNReachabilitySwift",
    "version": "0.0.2",
    "summary": "Super check net available in swift.",
    "description": "As we know, we already have reachability framework for us to choose. Such as the famous repository Reachability.nBUT we really need a tool for us to get the reachability, not the local connection!nApple doc tells us something about SCNetworkReachability API: "Note that reachability does not guarantee that the data packet will actually be received by the host."nThe called "reachability" we already know can only tell us the local connection status.These tools currently we know are all supported by the SCNetworkReachability API.nNow Reachability in swift check the net real can connect to server.",
    "homepage": "https://github.com/ymsheng/ReachabilitySwift",
    "license": "MIT",
    "authors": {
        "yangmaosheng": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/ymsheng/ReachabilitySwift.git",
        "tag": "0.0.2"
    },
    "source_files": [
        "ReachabilitySwift/MNReachability/*.swift",
        "ReachabilitySwift/MNReachability/FSM/*.swift",
        "ReachabilitySwift/MNReachability/Connection/*.swift",
        "ReachabilitySwift/MNReachability/Ping/*.swift"
    ],
    "exclude_files": "Classes/Exclude",
    "frameworks": [
        "Foundation",
        "UIKit"
    ]
}

Pin It on Pinterest

Share This