Reachability.swift
Reachability.swift copied to clipboard
Reachability for WWAN not working (Swift 2.3)
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")
}
}
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