在我的应用程序中,当我尝试获取数据Alamofire但存在连接问题时,随机显示error = Optional (Error Domain = NSURLErrorDomain Code = -1005 "The network connection was lost."
以便responseObject
为nil
。处理数据的最佳方法是什么,以便在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
})