ios - Alamofire - NetworkReachabilityManager doesn't work with .notReachable -
i have issue networkreachabilitymanager
alamofire
. tried test connection example code:
override func viewdidload() { super.viewdidload() let manager = networkreachabilitymanager(host: "www.apple.com") manager?.listener = { status in switch status { case .notreachable: print("network connection status - lost") case .reachable(networkreachabilitymanager.connectiontype.ethernetorwifi): print("network connection status - ethernet/wifi") case .reachable(networkreachabilitymanager.connectiontype.wwan): print("network connection status - wwan") default: break } } manager?.startlistening() }
when tried turn wifi off , received blank response. no response such "network connection status - lost".
but when tried turn on wifi , received result "network connection status - ethernet/wifi" in response. idea wrong .notreachable
? suggestion appreciated.
according alamofire
"make sure remember retain manager" create manager this
class a: uiviewcontroller{ let manager = networkreachabilitymanager(host: "www.apple.com") override func viewdidload() { super.viewdidload() // before start listening can check if (manager?.isreachableonethernetorwifi == true) { print("internet available") } else { print("internet not available") } manager?.startlistening() manager?.listener = { status in switch status { case .notreachable: print("network connection status - lost") case .reachable(networkreachabilitymanager.connectiontype.ethernetorwifi): print("network connection status - ethernet/wifi") case .reachable(networkreachabilitymanager.connectiontype.wwan): print("network connection status - wwan") default: break } } } }
Comments
Post a Comment