Search code examples
iosswiftalamofire

Not getting response from Alamofire


Using Alamofire for JSON response from remote. I have had a very weird issue. While running my app on a device connected through cable is working fine and getting all response. But when the device gets disconnected through cable response time getting increased to 5 minutes to 30 minutes and if I connect the device to charging or to MacBook again it's work fine but stuck if not connected.

    func getData()
    {
        let baseUrl = URL.init(fileURLWithPath: "")
        let headers:HTTPHeaders = ["Content-Type":"application/json"]
        Alamofire.request(baseUrl, method: .get, parameters: nil, encoding: URLEncoding.default, headers: headers)
        .responseJSON
        { response in
            switch(response.result) {
                case .success(_):
                    if response.result.value != nil{
                        let jsonData = response.result.value as? Dictionary<String,AnyObject>
                        print(jsonData)
                    }
                case .failure(_):
                    print(response.result.error!)
                    break
            }
        }
    }

Solution

  • Are you using any other class for Session manager? If yes then that may cause problem. So remove that one.