How to use NetworkReachabilityManager in Alamofire

前端 未结 10 1457
醉酒成梦
醉酒成梦 2020-12-02 14:31

I want functionality similar to AFNetworking in Objective-C with Alamofire NetworkReachabilityManager in Swift:

//Reachability detection
[[AFNet         


        
10条回答
  •  难免孤独
    2020-12-02 15:05

    I found the answer myself i.e by just writing a listener with closure as mentioned below:

    let net = NetworkReachabilityManager()
    
    net?.listener = { status in
        if net?.isReachable ?? false {
    
        switch status {
    
        case .reachable(.ethernetOrWiFi):
            print("The network is reachable over the WiFi connection")
    
        case .reachable(.wwan):
            print("The network is reachable over the WWAN connection")
    
        case .notReachable:
            print("The network is not reachable")
    
        case .unknown :
            print("It is unknown whether the network is reachable")
    
        }
    }
    
    net?.startListening()
    

提交回复
热议问题