错误代码= -1005随机,间歇性互联网和Alamofire

时间:2016-04-29 01:47:00

标签: ios swift xcode7 alamofire

在我的应用程序中,当我尝试获取数据Alamofire但存在连接问题时,随机显示error = Optional (Error Domain = NSURLErrorDomain Code = -1005 "The network connection was lost."以便responseObjectnil。处理数据的最佳方法是什么,以便在nil时再次拨打电话?

附上我对服务器的电话:

 
makeCall(dirurl, param: parame, completionHandler: { responseObject, error in

        print("responseObject = \(responseObject); error = \(error)")

        //here should control for the call is generated until it is different from nil

        self.datosRequest = responseObject!


        self.datosContenido = self.datosRequest["datos"] as! NSDictionary
        self.extractData()
        self.tableGastosComunes.reloadData()
        return
    })

func makeCall(dirurl: String, param : [String:NSObject], completionHandler: (NSDictionary?, NSError?) -> ()) {

    Alamofire.request(.POST, dirurl, parameters: param, encoding:.URL).responseJSON { response in

        switch response.result {
        case .Success(let value):
            completionHandler(value as? NSDictionary, nil)
        case .Failure(let error):
            completionHandler(nil, error)
        }
    }
}

print("responseObject = \(responseObject); error = \(error)") //here should control for the call is generated until it is different from nil self.datosRequest = responseObject! self.datosContenido = self.datosRequest["datos"] as! NSDictionary self.extractData() self.tableGastosComunes.reloadData() return })

0 个答案:

没有答案