ashleymills / Reachability.swift

Replacement for Apple's Reachability re-written in Swift with closures
MIT License
7.96k stars 948 forks source link

Reachability for WWAN not working (Swift 2.3) #177

Open burf2000 opened 7 years ago

burf2000 commented 7 years ago

So I am using the samples listed on this site and want to know when I have WIFI / Cellular and no connection. I have a 4G sim with data (checked the internet).

When I turn WIFI on it says WIFI is on however it does not also say Cellular is on (When it is) When I turn WIFI off it says Network not reachable (it actually fires twice, first it thinks there is Cellular, then not)

func reachabilityChanged(note: NSNotification) {

        let reachability = note.object as! Reachability

        if reachability.isReachable()
        {
            if reachability.isReachableViaWiFi() == true
            {
                print("Reachable via WiFi")
                wifiImage.image = UIImage(named: "white-wifi")
            }

            if reachability.isReachableViaWWAN() == true
            {
                print("Reachable via Cellular")
                mobileImage.image = UIImage(named: "white-mobile")
            }
        }
        else
        {
            print("Network not reachable")
            wifiImage.image = UIImage(named: "black-wifi")
            mobileImage.image = UIImage(named: "mobile")
        }
    }
hanab commented 7 years ago

is the libray working when there is both wifi and cellular connections? I am trying to use it to detect cellular network , and doesn't detect when there is both cellular and wifi network, it returns true for wifi and false for cellular