每次调用此函数时,我都会收到unacceptablStatusCode错误 Alamofire 4.0.0,Swift 3,Xcode 8。 如果我将acceptableStatusCode范围传递给200 ...< 500,它仍会给出相同的错误。 我是否在函数中有任何错误,因为前两个API工作正常或者它是alamofire 4.0.0 bug ???
func getTargetbyDistributor()
{
DispatchQueue.main.async {
SwiftLoader.show("Loading...", animated: true)
}
var param: [String: Any] = [String: Any]()
param = ["user_id":(UserDefaults.standard.object(forKey: "UserInformation") as! NSDictionary).value(forKey: "user_id"),"country_id":(UserDefaults.standard.object(forKey: "UserInformation") as! NSDictionary).value(forKey: "country_id"),"role_id":(UserDefaults.standard.object(forKey: "UserInformation") as! NSDictionary).value(forKey: "role_id"),"from_month_data":txtdate.text!,
"to_month_data":txtToDate.text!]
Alamofire.request(kUrlConstant + "getTargetbyDistributor", method: .post , parameters: param)
.validate()
.responseJSON { response in
switch response.result {
case .success(_):
DispatchQueue.main.async {
SwiftLoader.hide()
}
let str = NSString(data: response.data!, encoding:String.Encoding.utf8.rawValue)
var jsonResult = [String:AnyObject]()
do
{
jsonResult = try JSONSerialization.jsonObject(with: response.data!, options: []) as! [String:AnyObject]
print(jsonResult)
if jsonResult["status"] as! Int == 1
{
print(jsonResult)
self.txtdate.text = ""
self.txtToDate.text = ""
self.bgScrollView.isHidden = false
self.btnNext.isHidden = false
self.PaginationView.isHidden = false
self.btnPrev.isHidden = false
self.bgScrollView.bounces = false
self.bgScrollView.bouncesZoom = false
let hight = CGFloat(((jsonResult["data"] as! NSArray).count * 40) + 50)
self.bgScrollView.frame = CGRect(x: self.bgScrollView.frame.origin.x,y: self.bgScrollView.frame.origin.y,width: self.bgScrollView.frame.size.width,height: hight)
self.PaginationView.frame = CGRect(x: self.PaginationView.frame.origin.x,y: self.bgScrollView.frame.origin.y + self.bgScrollView.frame.size.height + 6,width: self.PaginationView.frame.size.width,height: self.PaginationView.frame.size.height)
if (((jsonResult["data"] as! NSDictionary).object(forKey: "target_data") as! NSDictionary).object(forKey: "month_data") as! NSArray).count >= 1
{
self.headerArray = (((jsonResult["data"] as! NSDictionary).object(forKey: "target_data") as! NSDictionary).object(forKey: "month_data") as! NSMutableArray)
}
if (((jsonResult["data"] as! NSDictionary).object(forKey: "target_data") as! NSDictionary).object(forKey: "data") as! NSArray).count >= 1
{
self.dataTableArray = (((jsonResult["data"] as! NSDictionary).object(forKey: "target_data") as! NSDictionary).object(forKey: "data") as! NSMutableArray)
}
self.header()
self.tblView.reloadData()
}
else
{
let alertController = UIAlertController(title: "Alert", message: jsonResult["message"] as? String, preferredStyle: .alert)
let OKAction = UIAlertAction(title: "OK", style: .default) { (action:UIAlertAction!) in
return false;
}
alertController.addAction(OKAction)
self.present(alertController, animated: true, completion:nil)
}
} catch let error as NSError {
print(str);
print(error)
DispatchQueue.main.async {
SwiftLoader.hide()
}
}
print("Validation Successful")
case .failure(let error):
print(error)
DispatchQueue.main.async {
SwiftLoader.hide()
}
}
}
}