Bez popisu

Ashley Mills f31b459d96 Update podspec před 10 roky
Reachability Sample 47f1b5061f Update version to 2.0-beta5 před 10 roky
Reachability Test 108ab38b88 Update version před 10 roky
.gitignore 79f8d2502f Add test harness app před 11 roky
LICENSE acc3ef30f8 Initial check in před 11 roky
README.md 7413178d23 Merge branch 'master' into develop před 10 roky
Reachability.swift 7413178d23 Merge branch 'master' into develop před 10 roky
ReachabilitySwift.podspec f31b459d96 Update podspec před 10 roky

README.md

Reachability.swift

Replacement for Apple's Reachability re-written in Swift with closures

Inspired by https://github.com/tonymillion/Reachability

NOTES:

  • If an application has the privacy option “Use cellular data” turned off, the Reachability class still reports isReachable() to be true. There is currently no (non-private) API to detect this. If you need this feature, please raise file a bug report with Apple to get this fixed. See devforums thread for details: https://devforums.apple.com/message/1059332#1059332

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. To install Reachability.swift with CocoaPods:

  1. Make sure CocoaPods is installed.

  2. Update your Podfile to include the following:

    use_frameworks!
    pod 'ReachabilitySwift', git: 'https://github.com/ashleymills/Reachability.swift'
    
  3. Run pod install.

Manual

Just drop the Reachability.swift file into your project. That's it!

Example - closures

let reachability = Reachability.reachabilityForInternetConnection()

reachability.whenReachable = { reachability in
    if reachability.isReachableViaWiFi() {
        println("Reachable via WiFi")
    } else {
        println("Reachable via Cellular")
    }
}
reachability.whenUnreachable = { reachability in
    println("Not reachable")
}

reachability.startNotifier()

Example - notifications

let reachability = Reachability.reachabilityForInternetConnection()

NSNotificationCenter.defaultCenter().addObserver(self, selector: "reachabilityChanged:", name: ReachabilityChangedNotification, object: reachability)

reachability.startNotifier()

and

func reachabilityChanged(note: NSNotification) {

    let reachability = note.object as! Reachability

    if reachability.isReachable() {
        if reachability.isReachableViaWiFi() {
            println("Reachable via WiFi")
        } else {
            println("Reachable via Cellular")
        }
    } else {
        println("Not reachable")
    }
}

Want to help?

Got a bug fix, or a new feature? Create a pull request and go for it!

Let me know!

If you use Reachability.swift, please let me know about your app and I'll put a link here… and tell your friends!

Cheers, Ash